2015-09-23 21 views
0

,我有以下数据:GGPLOT2:添加额外的指南菱形ppints

groups = c(rep(1,5),rep(2,5),rep(3,5)) 
scores = c(seq(1,5),seq(1,5),seq(1,5)) 
times1 = rnorm(15, mean = 3 , sd = 2) 
times2 = rnorm(15, mean = 1 , sd = 0.5) 
df = data.frame(groups,scores, times1,times2) 

,我有以下情节

df = data.frame(groups,scores, times1,times2) 
plt = ggplot(df, aes(x = scores, y = times1, color = factor(groups))) 
plt = plt + geom_point(cex = 4) + geom_line() + theme_bw() 
plt = plt + geom_point(aes(x = scores, y=times2),pch = 23, cex =4)+ geom_line(aes(x = scores, y=times2)) 
plt = plt + facet_wrap(~ groups, ncol = 4, scales = "free_x") 
plt 

导致

enter image description here

如何添加钻石点的指南,以及如何更改钻石点e的每个相应的指南。

回答

1

如果你想要一个传说的东西,它应该被指定为审美。也许类似

ggplot(df, aes(x = scores, color = factor(groups))) + 
    geom_point(aes(y=times1, shape="times1"), cex = 4) + 
    geom_line(aes(y=times1)) + 
    geom_point(aes(y=times2, shape="times2"),cex =4) + 
    geom_line(aes(y=times2)) + 
    facet_wrap(~ groups, ncol = 4, scales = "free_x") + theme_bw() 

不是mannally加层,它甚至会更好,如果你正确地rehaped数据到ggplot perfers

ggplot(reshape2::melt(df, id=c("groups","scores")), 
    aes(x=scores,y=value, shape=variable, color=factor(groups))) + 
    geom_point() + 
    geom_line() + 
    facet_wrap(~groups) 
+0

,才有可能从组指南中删除界的格式并保持颜色和线条? – kolonel

+0

只需放下geom_point()参数 - 注意ggplot将不同的绘图元素层叠在一起 - geom_line提供线条,geom_point点(形状) - 都从基础层美学继承它们的着色 – CMichael

+0

@CMichael我熟悉你在说什么,但我不能因为我仍然需要点的指导而放弃geom_point。 – kolonel