![](/img/trans.png)
[英]How can I suppress the vertical gridlines in a ggplot2 plot while retaining the x-axis labels?
[英]How to plot two lines on one plot with ggplot2 while specifying order of the x-axis labels?
數據在“統計”中:
run valence mean sd sem
Nnf1_mINS n 2.1 .5 .01
Nnf2_mINS p 3.2 .2 .01
Nobs_mINS n 2.3 .1 .02
這是我的代碼:
ggplot(stats,aes(x=run,y=mean,color=valence,group=1))+
geom_point() +
geom_line()+
geom_errorbar(aes(ymin = mean - sem, ymax = mean + sem),
width = 0.2,
position = position_dodge(0.9))
3個問題:
stats$run <- factor(stats$run, levels = c("Nobs_mINS","Nnf1_mINS","Nnf2_mINS"))
但是要在一個圖上繪制 2 條線,不能有因子變量。 這是錯誤:“geom_path:每個組僅包含一個觀察值。您需要調整組審美嗎?” 由於這篇文章,我通過添加“group=1”修復了這個錯誤: ggplot2 折線圖給出了“geom_path:每個組只包含一個觀察值。你需要調整組美學嗎?”
好吧,group = valence 解決了這個問題! 這是編輯后的代碼:
ggplot(stats,aes(x=run,y=mean,color=valence,group=valence))+
geom_point() +
geom_line()+
geom_errorbar(aes(ymin = mean - sem, ymax = mean + sem),
width = .2,
position = position_dodge(.09))+
theme(text = element_text(size=15),
axis.text.x = element_text(angle=0, hjust=1))+
scale_y_continuous(limits = c(-0.22, 0.1))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.