我的主要目标是在我的情节中对元素进行不同的着色。为此,我manually
添加了一个额外的列,其中每个列都有所需的颜色category
:
mtcars$color[mtcars$carb = 4] = '#F98866'
mtcars$color[mtcars$carb = 3] = '#68829E'
mtcars$color[mtcars$carb = 2] = '#FF420E'
mtcars$color[mtcars$carb = 1] = '#89DA59'
p <- ggplot(mtcars) +
geom_point(aes(wt, mpg,
size = disp,
color = mtcars$color))# + scale_color_manual(values = mtcars$color)
But when I run the above code, I get this as an output:
Instead of my specified
colors, I get the preset ggplot
colors.
但如果我取消最后一行的注释,我部分地得到我正在寻找的东西——只有我想要的一种颜色。
![enter image description here](https://i.stack.imgur.com/Mwn7L.png)
如何解决这个问题?
ggplot(mtcars) +
geom_point(aes(wt, mpg, size = disp, color = color)) +
scale_color_identity(guide = 'legend')
![enter image description here](https://i.stack.imgur.com/XzTUp.png)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)