如何更改ggplot2中的线条和形状颜色? [英] How to change line and shape colours in ggplot2?
本文介绍了如何更改ggplot2中的线条和形状颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样一个数据框:
x < - data.frame(time = c('1 ('','2','3'),perc = c(0.2,0.4,0.6,0.3,0.55,0.69,0.2,0.22,0.35),type = c(rep('a',3),rep(' b',3),rep('c',3)))
并且想要做一个(下图),但使用这些不同的颜色 c('#0023a0','#f9a635','#bebec0')
:
ggplot(x,aes(time,perc,group = type,color = type,shape = type))+ geom_point(size = 4)+ geom_line(size = 1)
scale_colour_hue , code> scale_shape_discrete 和 scale_fill_manual
,但没有任何成功。
解决方案
你究竟做了什么?这似乎适用于我:
ggplot(x,aes(时间,perc,组=类型,pch =类型,颜色)=
geom_point()+
geom_line()+
scale_colour_manual(values = c('#0023a0','#f9a635','#bebec0'))
I have a data frame like this one:
x <- data.frame(time = c('1', '2', '3'), perc = c(0.2, 0.4, 0.6, 0.3, 0.55, 0.69, 0.2, 0.22, 0.35), type=c(rep('a', 3), rep('b', 3), rep('c', 3)))
and want to do a plot like this (below) but using these different colors c('#0023a0', '#f9a635', '#bebec0')
:
ggplot(x, aes(time, perc, group=type, colour=type, shape=type)) + geom_point(size=4) + geom_line(size=1)
I have already tried different ways using scale_colour_hue
, scale_shape_discrete
and scale_fill_manual
, but without any success.
解决方案
What exactly did you try? This seems to work for me:
ggplot(x, aes(time, perc, group = type, pch = type, colour = type)) +
geom_point() +
geom_line() +
scale_colour_manual(values= c('#0023a0', '#f9a635', '#bebec0'))
这篇关于如何更改ggplot2中的线条和形状颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文