Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R中mschart数据标签的字体大小_R_List_Mschart - Fatal编程技术网

R中mschart数据标签的字体大小

R中mschart数据标签的字体大小,r,list,mschart,R,List,Mschart,我正在将一些柱状图从ggplot2更改为mschart,这样公司业务部门的同事就可以在MS Word中缩放柱状图、根据需要更改标题等,而无需重新生成PNG或SVG文件。我可以向条形图添加标签,并可以使用图表标签文本设置大小和颜色,但前提是我识别每个系列。文档中说,设置一个系列将强制图表标签文本将该值应用于列表中的所有系列,但我无法让它工作——除非我声明每个系列,否则标签不会调整大小 这是我的密码: # create the chart my_msbarchart <- ms_barchar

我正在将一些柱状图从ggplot2更改为mschart,这样公司业务部门的同事就可以在MS Word中缩放柱状图、根据需要更改标题等,而无需重新生成PNG或SVG文件。我可以向条形图添加标签,并可以使用图表标签文本设置大小和颜色,但前提是我识别每个系列。文档中说,设置一个系列将强制图表标签文本将该值应用于列表中的所有系列,但我无法让它工作——除非我声明每个系列,否则标签不会调整大小

这是我的密码:

# create the chart
my_msbarchart <- ms_barchart(data = df, x = "Category", y = "count", group = "Gender")

# chart label details
# How can I generalize this statement so that when I call my_label_text
# I don't need to specify each serie and chart?

my_label_text <- list(Female = fp_text(font.size = 8, color = "black"), 
                      Male = fp_text(font.size = 8, color = "black")) 

# add label text details to chart
my_msbarchart <- chart_labels_text(my_msbarchart, values=my_label_text)

# add the labels to the chart
my_msbarchart <- chart_data_labels(
  my_msbarchart,
  num_fmt = "0",
  position = "outEnd",
  show_val = TRUE,
)  

# function call to produce Word doc with chart
# Once I work out these chart labeling details, I will add the code to my function

gen_docx(my_msbarchart, file = "myDoc.docx") 
#创建图表
我的兄弟
my_label_text <- list(fp_text(font.size = 8, color = "black")
```
# The set of values I need to turn into a list of 'Male' and 'Female', which are the two values I have in 'Gender'
cow <- as.list(df$Gender)

# Take the list of all values and reduce the list to the two unique ones, 'Male' and 'Female'
# Append the rest of fp_text for the data label
cow <- paste0(unique(cow),"=fp_text(font.size=8,color='black')")

# Turn it back into a list
cow <- as.list(cow)
print(cow)

[[1]]
[1] "Female=fp_text(font.size=8,color='black')"

[[2]]
[1] "Male=fp_text(font.size=8,color='black')"

# Obviously, such a list won't work, 
# as fp_text looks like a string to data_label_text.

# If I create the list manually, fp_text runs properly
# and produces the results needed to produce the data labels.

cow <- list(Female=fp_text(font.size=8,color='black'),Male=fp_text(font.size=8,color='black'))
print(cow)

$Female
  size italic  bold underlined color     shading fontname vertical_align
1    8  FALSE FALSE      FALSE black transparent    Arial       baseline

$Male
  size italic  bold underlined color     shading fontname vertical_align
1    8  FALSE FALSE      FALSE black transparent    Arial       baseline
```