2015-09-23 20 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