我想在一张图中创建两条温度曲线。
我的数据框如下所示:
temp <- read.table(text = " Time Temp1 Temp2
1 00:00 18.62800 18.54458
2 00:10 18.60025 18.48283
3 00:20 18.57250 18.36767
4 00:30 18.54667 18.36950
5 00:40 18.51483 18.36550
6 00:50 18.48325 18.34783
7 01:00 18.45733 18.22625
8 01:10 18.43767 18.19067
9 01:20 18.41583 18.22042
10 01:30 18.39608 18.21225
11 01:40 18.37625 18.18658
12 01:50 18.35633 18.05942
13 02:00 18.33258 18.04142", header = T)
如何通过仅在 x 轴上显示每小时(24 小时)来获得清晰的曲线(像折线图一样线上没有边缘)?
我正在考虑使用 ggplot2,但我仍在学习 R 基础知识。
如果您想绘制所有值但仅将完整小时作为 x 轴标签,您可以使用以下命令绘制数据ggplot
封装并使用scale_x_discrete()
选项来指定breaks
.
library(ggplot2)
is_full_time <- grepl(':00', temp$Time)
ggplot(temp, aes(x = Time, y = Temp1, group = 1)) + geom_line() + scale_x_discrete(breaks = temp$Time[is_full_time])
http://ggplot2.tidyverse.org/reference/scale_discrete.html http://ggplot2.tidyverse.org/reference/scale_discrete.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)