【发布时间】:2022-01-23 12:36:40
【问题描述】:
我 2 周前刚开始 R 编程,我有一个带有 1 个 x 轴和 2 个 y 轴的案例研究图……我在 48 小时内尽我所能用 Legend 替换 Title……但我做不到找出问题所在,希望我能得到你们的帮助。
剧情:
ggplot(libya_covid, aes(x=date)) +
geom_line( aes(y=new_tests), size=2, color='blue') +
geom_line( aes(y=new_cases / 1), size=2, color='darkorange') +
xlab("Date")+
scale_y_continuous(
# Features of the first axis
name = "New Tests",
# Add a second axis and specify its features
sec.axis = sec_axis(~.*1, name= "New Cases")
) +
theme_bw() +
theme(
axis.title.y = element_text(color = 'blue', size=13),
axis.title.y.right = element_text(color = 'darkorange', size=13)
) +
ggtitle("New Tests Versus New Cases Analysis")
现在我只想从左右删除 Y 标题并在左上角添加简单图例
提前致谢。
【问题讨论】:
-
欢迎堆栈溢出。请通过粘贴数据样本使您的问题可重现:使用
dput(head(your_data_sample, n))其中n足以证明问题的数据。这使得其他人更容易复制数据以测试和验证解决方案。 minimal reproducible example