gpt4 book ai didi

r - 在ggplot中设置y轴中断

转载 作者:行者123 更新时间:2023-12-03 23:00:15 27 4
gpt4 key购买 nike

我在设置代码中断时遇到困难,我尝试添加breaks = seq(0,100,by = 20),但似乎无法使其正常工作。本质上,我希望Y轴从0-100开始,每20跳一次。

    YearlyCI <- read.table(header=T, text='
Station Year CI se
M-25 2013 56.57098 1.4481561
M-45 2013 32.39036 0.6567439
X-2 2013 37.87488 0.7451653
M-25 2008 74.5 2.4
M-45 2008 41.6 1.1
M-25 2004 82.2 1.9
M-45 2004 60.6 1.0
')


library(ggplot2)
ggplot(YearlyCI, aes(x=Year, y=CI, colour=Station,group=Station)) +
geom_errorbar(aes(ymin=CI-se, ymax=CI+se), colour="black", width=.2) +
geom_line(size=.8) +
geom_point(size=4, shape=18) +
coord_cartesian(ylim = c(0, 100)) +
xlab("Year") +
ylab("Mean Condition Index") +
labs(fill="") +
theme_bw() +
theme(legend.justification=c(1,1), legend.position=c(1,1))

最佳答案

您需要添加

+ scale_y_continuous(breaks = seq(0, 100, by = 20))

编辑:对于以下注释,仅当轴已在适当范围内时,此方法才有效。要强制执行此范围,可以按如下所示扩展代码:

+ scale_y_continuous(limits = c(0, 100), breaks = seq(0, 100, by = 20))

关于r - 在ggplot中设置y轴中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22818899/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com