Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.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 ggplot2图例中带有组合项目的项目变更单_R_Ggplot2 - Fatal编程技术网

R ggplot2图例中带有组合项目的项目变更单

R ggplot2图例中带有组合项目的项目变更单,r,ggplot2,R,Ggplot2,我使用ggplot2绘制散点图,其中包含分组和非分组的geom_smooth()。我希望未分组平滑的条目出现在图例的顶部或底部,但图例是按字母顺序排序的 my.colors <- c('4' = 'red', 'f' = 'green', 'r' = 'blue', 'all' = 'black') ggplot(mpg, aes(displ, hwy)) + geom_point(aes(color = drv), alpha = 1/3) + theme_bw() + geom

我使用
ggplot2
绘制散点图,其中包含分组和非分组的
geom_smooth()
。我希望未分组平滑的条目出现在图例的顶部或底部,但图例是按字母顺序排序的

my.colors <- c('4' = 'red', 'f' = 'green', 'r' = 'blue', 'all' = 'black')
ggplot(mpg, aes(displ, hwy)) +
  geom_point(aes(color = drv), alpha = 1/3) + theme_bw() +
  geom_smooth(aes(color = drv), method = 'lm') +
  geom_smooth(aes(color = 'all'), method = 'lm') +
  scale_color_manual(name = "Drive Types", values = my.colors)
my.colors是否使用中断

my.colors <- c('4' = 'red', 'f' = 'green', 'r' = 'blue', 'all' = 'black')
ggplot(mpg, aes(displ, hwy)) +
  geom_point(aes(color = drv), alpha = 1/3) + theme_bw() +
  geom_smooth(aes(color = drv), method = 'lm') +
  geom_smooth(aes(color = 'all'), method = 'lm') +
  scale_color_manual(name = "Drive Types", values = my.colors, 
                     breaks=c("all", "4", "f", "r"))

my.colors这回答了我的一个类似问题,那就是,“如果我只想展示一些图例怎么办?”在这个例子中,
breaks=c(“all”,“r”)
是我所需要的。