我正在尝试将y轴标签和刻度标记移到右侧,但我收到此错误:
scale_y_continuous出错(position =“right”,limits = c(62,69),breaks = c(61,:unused argument(position =“right”)
我在这个功能中是否更新了一些我不知道的内容?
有关如何修改我的脚本以将整个y轴移动到图表右侧的任何建议将不胜感激。
代码
library(ggplot2)
df <- data.frame(weeks = c(-1, 0, 1, 2, 3, 4),
mean = c(64, 65, 66, 66, 66, 67),
lowerCI = c(63.4, 64.9, 64.5, 63.8, 62.1, 66.8),
upperCI = c(65.6, 65.1, 66.5, 67.2, 68.9, 67.2))
sp_ts <- ggplot(data = df,
aes(x = weeks,
y = mean))
sp_ts +
geom_point(shape = 15,
size = 4) +
geom_errorbar(aes(ymin = lowerCI,
ymax = upperCI),
width = 0.05,
size = 0.5) +
labs(title = "Scatterplot of means",
x = "Weeks",
y = "Means") +
scale_x_continuous(limits = c(-1, 4),
breaks = c(-1, 0, 1, 2, 3, 4)) +
scale_y_continuous(position = "right",
limits = c(62, 69),
breaks = c(61, 62, 63, 64, 65, 66, 67, 68, 69)) +
annotate("rect", xmin = -Inf, xmax = 2, ymin = -Inf, ymax = Inf, fill = "light blue", alpha = 0.2) +
annotate("rect", xmin = 2, xmax = Inf, ymin = -Inf, ymax = Inf, fill = "blue", alpha = 0.2) +
theme_bw() +
theme(panel.grid.minor = element_blank())