r - ggplot2-scale_colour_manual和scale_shape手动问题

标签 r ggplot2

我希望将 4 种颜色(红、蓝、绿和黑)与 4 种不同的形状(形状编号 15、16、17、19)组合起来。可以分配这些组合吗?我使用下面的代码做到了,虽然颜色改变了,但形状没有改变。

这是到目前为止的代码:

Lplot<- ggplot(totdt, aes(x=X1, y=Y2, color = Sp, fill=Sp)) + geom_polygon(data=zone2, alpha=.1)  + geom_point(size = 3)  
Lplot<- Lplot+ scale_shape_manual(values=c(15,16,17,19, 15,16,17,19, 15,16,17,19, 15,16,17,19 ))
Lplot<- Lplot+ scale_colour_manual(values = c("red", "blue", "green", "black","red", "blue", "green", "black","red", "blue", "green", "black","red", "blue", "green", "black","red" ))

最佳答案

您必须设置要与 scale_shape_manual 一起使用的 shape 美学。例如:

data('"mtcars"')
cars <- mtcars %>% group_by(gear, cyl = as.factor(cyl)) %>% summarise(n = n())

ggplot(cars, aes(x = gear, y = n)) +
    geom_line(aes(color = cyl)) + geom_point(aes(shape = cyl)) +
    scale_shape_manual(values = c(15, 16, 17)) +
    scale_color_manual(values = c('red', 'blue', 'green'))

关于r - ggplot2-scale_colour_manual和scale_shape手动问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42176203/

相关文章:

r - 将列表 append 到 R 中的数据框

r - 如何在 ggplot2 中使用 facet_grid 获得适合的长标签?

r - 错误 ggplotly : VECTOR_ELT() can only be applied to a 'list' , 不是 'NULL'

r - 使用 gg voronoi 按因子着色时手动设置 Voronoi 图的颜色

r - 如何使用 R 包 'hash' 访问 R 中的整数键

javascript - Shiny 的 ui.R 是否支持在每个带有 tabsetPanel 的 tabPanel 上包含 html 页面?

r - 从 bash 调用 R 脚本时退出代码

r - 如何使用dplyr和整洁的评估以编程方式过滤数据帧?

r - 如何更改 ggplot 中这个定制设计图例的背景颜色?

r - ggplot2 散点图标签