r - R:使用 scale_y_continuous(sec.axis) 和 coord_trans(log10) 绘制两个 y 轴图
问题描述
我正在尝试绘制一个 2y 轴图;左边是实际值,右边是百分比值。除此之外,我需要在左侧 y 轴上应用 coord_trans 以便更好地可视化小值。但是,当我这样做时,右侧的标签不会出现。
这里的数据(示例)
这里的代码
DAXIS <- ggplot(x1, aes(hour, value_T, colour=season, linetype = variable)) +
geom_line(size = 1) +
scale_linetype_manual(c("var"), values=c("solid", "dashed", "dotted"))+ # here to change one name
geom_point(aes(shape = season), size = 1)+
labs(x = "hour", y = "T") +
scale_x_continuous(breaks = c(0, 6, 12, 18, 23), labels= c(0, 6, 12, 18, 24))+
scale_y_continuous("T",
sec.axis = sec_axis(~./2.341598, name = " [%] ",
breaks=c(0.2135294, 0.4270588, 0.6405882, 0.8541176,1),
labels = function(b) { paste0(round(b * 100, 0), "%")}))+
#coord_trans(y = "log10", breaks=c(0.5,1,1.5,1.903738), labels = c(0.5,1,1.5,1.9))+ # attemp 1
#coord_trans(y = "log10")+ # attemp 2
scale_color_aaas()+
theme_bw()+
theme(legend.direction = "horizontal", legend.position = "bottom", legend.key = element_blank(),
legend.background = element_rect(fill = "white", colour = "gray30")) +
theme(legend.position="bottom",
text=element_text(size=18),
axis.text.x = element_text(size=15),
axis.text.y = element_text(size=15))
DAXIS
很感谢任何形式的帮助
解决方案
推荐阅读
- java - 控制台整体执行程序的问题
- c++ - for 循环条件 (str1[i] && str2[i]) 是什么意思?
- jenkins - 在 Clearcase 中使用 Jenkins 创建分支和配置文件
- javascript - 使用组件反应 Typescript 自动完成
- rxjs - 关于 2 个 rxjs 可观察对象和一个计时器的问题
- xcode - Xcode lldb 无法附加到 MacOS 系统程序 /bin/cp -“不允许附加到进程。”
- testing - 有没有办法测试 roblox 游戏?
- python - 在python顶部水平对齐图例
- c# - 如何更快地绘制数据
- python - 根据 pandas 数据框中的相邻列将 NaN 值替换为特定文本