Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/64.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 更改ggplot中的颜色方案并能够编辑图例_R_Plot_Ggplot2 - Fatal编程技术网

R 更改ggplot中的颜色方案并能够编辑图例

R 更改ggplot中的颜色方案并能够编辑图例,r,plot,ggplot2,R,Plot,Ggplot2,除了调整图例外,我还尝试更改ggplot中的配色方案。然而,我似乎只能做其中一个,最近的命令覆盖了另一个 我这里有一个MWE,所以这只是创建了一个虚拟图,其中有一个自定义图例,图例标题和因子变量中有多个单词 library(ggplot2) set.seed(17) df <- data.frame(method=sample(c('A', 'B', 'C'), 20, replace=T), score=runif(20), grou

除了调整图例外,我还尝试更改ggplot中的配色方案。然而,我似乎只能做其中一个,最近的命令覆盖了另一个

我这里有一个MWE,所以这只是创建了一个虚拟图,其中有一个自定义图例,图例标题和因子变量中有多个单词

library(ggplot2)

set.seed(17)
df <- data.frame(method=sample(c('A', 'B', 'C'), 20, replace=T),
             score=runif(20),
             group=sample(0:1, 20, replace=T))
ggplot(df, aes(x=method, y=score, fill=factor(group))) +
  geom_boxplot() +
  scale_fill_discrete("Multi word title", breaks=c(0, 1), labels=c('Group 1', 'Group 2'))

您只需要一个填充刻度。将标签和标题放在定义的比例内,它使用与其他比例相同的参数

ggplot(df, aes(x=method, y=score, fill=factor(group))) +
      geom_boxplot() +
      scale_fill_Publication("Multi word title", breaks=c(0, 1), 
                          labels=c('Group 1', 'Group 2'))

答案中的颜色规格发生了什么变化?
ggplot(df, aes(x=method, y=score, fill=factor(group))) +
  geom_boxplot() +
  scale_fill_discrete("Multi word title", breaks=c(0, 1), 
                      labels=c('Group 1', 'Group 2')) +
  scale_fill_Publication()
ggplot(df, aes(x=method, y=score, fill=factor(group))) +
      geom_boxplot() +
      scale_fill_Publication("Multi word title", breaks=c(0, 1), 
                          labels=c('Group 1', 'Group 2'))