【问题标题】:R mschart turn off line smoothingR mschart关闭线平滑
【发布时间】:2021-07-11 22:27:33
【问题描述】:

我正在使用 mschart 0.2.6 版在 R 中为 powerpoint 绘制折线图。默认情况下,我得到平滑的线条,但不希望这样。如何关闭它?

我在 github 上找到了以下功能请求,但它已关闭,我不确定它是如何解决的: https://github.com/ardata-fr/mschart/issues/25

这是一个工作示例:

library(officer)
library(mschart)

dat<-data.frame(Year=c(rep("2010",3), rep("2011",3), rep("2012",3)),
            Fruit=c(rep(c("Apples","Oranges","Pears"),3)),
            Count = c(332,229,168,
                      223,189,225,
                      321,378,261), stringsAsFactors=F)

line_chart <- ms_linechart(data = dat, x = "Year",y = "Count", group="Fruit")

doc <- read_pptx()
doc <- add_slide(doc, layout = "Title and Content", master = "Office Theme")
doc <- ph_with(x = doc, value = c("Fruit"),
             location = ph_location_type(type = "title") )
doc <- ph_with(doc, line_chart, location = ph_location_type(type="body"))
fileout <- "./Test.pptx" 
print(doc, target = fileout)

这是它产生的结果。请注意左下方选中的平滑线选项:

【问题讨论】:

    标签: r mschart officer


    【解决方案1】:

    ms_linechart 对象通过管道(或包装)到chart_data_smooth() 函数中,并将values 设置为0。

    library(officer)
    library(mschart)
    library(tidyverse)
    
    line_chart <- ms_linechart(data = dat, x = "Year",y = "Count", group="Fruit") %>% 
                  chart_data_smooth(values = 0) # Here is the code that sets lines to straight.
    
    doc <- read_pptx()
    doc <- add_slide(doc, layout = "Title and Content", master = "Office Theme")
    doc <- ph_with(x = doc, value = c("Fruit"),
                   location = ph_location_type(type = "title") )
    doc <- ph_with(doc, line_chart, location = ph_location_type(type="body"))
    fileout <- "./Test2.pptx" 
    print(doc, target = fileout)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多