如何使用Hex更改颜色,使用单行更平滑

时间:2013-07-02 06:06:27

标签: r ggplot2 smooth

bay <- structure(list(wbi = c(0.08, 0.08, 0.02, 0.26, 0.08, 0.08, 0.02, 
0.08, 0.08, 0.03, 0.26, 0.02, 0.08, 0.03, 0.08, 0.03, 0.08, 0.03, 
0.03, 0.02, 0.03, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.03, 0.08, 
0.08), medprice.n2 = c(39.99, 54.99, 44.99, 59.99, 49.99, 44.99, 
59.99, 54.99, 39.99, 49.99, 49.99, 59.99, 54.99, 44.99, 39.99, 
54.99, 39.99, 49.99, 44.99, 59.99, 39.99, 44.99, 49.99, 54.99, 
44.99, 54.99, 39.99, 39.99, 49.99, 59.99)), .Names = c("wbi", 
"medprice.n2"), row.names = c(2L, 21L, 23L, 46L, 60L, 62L, 63L, 
64L, 66L, 67L, 72L, 74L, 76L, 77L, 78L, 80L, 82L, 83L, 85L, 89L, 
91L, 92L, 95L, 96L, 97L, 102L, 103L, 104L, 106L, 108L), class = "data.frame")

以下代码生成带红线的图表。我想将红线更改为#5182BA。我将下面第六行中的"red"替换为hex #5182BA,但不起作用(出现红线)。我在这个问题上搜索过高低,查阅了我的ggplot2书籍,但未能找到解决方案。谢谢

gg <- subset(bay, hp_quota == 1)
reg <- with(gg, lm(wbi ~ medprice.n2))
summary(reg)
ddply(gg, .(medprice.n2), summarise, mean=round(mean(wbi(q2final), na.rm=TRUE), 2))
ggplot(gg, aes( x = medprice.n2, 100*(y = wbi(q2final))))  + 
stat_smooth( method = lm, se = FALSE, size = 1.3, colour="red", fill="red")
coord_cartesian(ylim = c(0,25)) +  
scale_y_continuous(breaks= c(0, 5, 10, 15, 20, 25)) + 
theme(panel.grid.minor = element_blank()) +
theme(text=element_text(family="Arial", size=16)) +
theme(axis.ticks = element_blank()) + 
theme(axis.title.x = element_blank()) + 
#theme(axis.text.y = element_blank()) + 
theme(axis.title.y = element_blank()) + 
theme(axis.text.x = element_blank()) +
theme(legend.position = "none"))

1 个答案:

答案 0 :(得分:0)

尽管你的大部分代码都不起作用且不可重现,将“red”更改为“5182BA”似乎工作正常。

ggplot(bay, aes(x=medprice.n2, y=wbi)) + 
    geom_smooth(method=lm, size=1.3, colour="#5182BA")