我已经做了一个噩梦,对一个传奇问题进行了一段时间的排序,现在用geom_point
进行geom_smooth
我最终在我的情节上有两个不同的传说,并试着像我一样我可能无法弄清楚如何将它们组合成更有用的东西。
情节代码是......
require(ggplot2)
require(scales)
require(cowplot)
palette <- scales::hue_pal()(3)
ggplot(df.Overview, aes(x=datePublished, y=sentiment, colour = type, group=type, linetype = type)) +
geom_point(aes(shape=factor(type)), size=3.5, position=position_jitter(width=0.3), alpha = 0.5) +
geom_smooth(fullrange = TRUE, alpha = .25, show_guide = TRUE) +
scale_x_date(breaks = "1 week", labels=date_format("%b-%d"), limits = c(overviewStartDate,overviewEndDate)) + # limit plot to overview dates
scale_y_continuous(limits =c(-1,1), oob=squish) + # set upper and lower bounds of Y axis
theme_bw() +
background_grid(major = "xy", minor = "none") +
labs(x = "", y = "Sentiment Index") +
scale_colour_manual( values = palette,
name="GSE",
breaks=c("sentiment_TitleDescMean", "sentiment_body"),
labels = c("x\u0304 (Title & Desc)", "Body") ) +
scale_shape_manual( values = c('sentiment_TitleDescMean' = 17, 'sentiment_body'= 15),
name="Story Part ",
breaks=c("sentiment_TitleDescMean", "sentiment_body"),
labels = c("x\u0304 (Title & Desc)", "Body") ) +
scale_linetype_discrete(name="GSE",
breaks=c("sentiment_TitleDescMean", "sentiment_body"),
labels = c("x\u0304 (Title & Desc)", "Body") ) +
theme(legend.key=element_rect(fill='white'), legend.position=c(.05,.75), legend.background = element_rect(fill="white", size=0.5, linetype="solid", colour ="grey30")) # set legend position
我真正想要的......
legend.position
参数。任何人都可以帮忙解决我怀疑正在排序的scale_
部分
答案 0 :(得分:2)
Heroka的评论为如何整齐地结合传说的主要问题提供了答案。超级简单...将通话更改为scale
,以便每个name="xxx"
都相同。
...正是如此
scale_colour_manual( values = palette,
name="Story Part",
breaks=c("sentiment_TitleDescMean", "sentiment_body"),
labels = c("x\u0304 (Title & Desc)", "Body") ) +
scale_shape_manual( values = c('sentiment_TitleDescMean' = 17, 'sentiment_body'= 15),
name="Story Part",
breaks=c("sentiment_TitleDescMean", "sentiment_body"),
labels = c("x\u0304 (Title & Desc)", "Body") ) +
scale_linetype_discrete(name="Story Part",
breaks=c("sentiment_TitleDescMean", "sentiment_body"),
labels = c("x\u0304 (Title & Desc)", "Body") )