温度曲线在R [英] Temperature curve in R
本文介绍了温度曲线在R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在一个绘图中创建两条温度曲线。
我的Dataframe如下所示:
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,h eader = T)
如何获得干净的曲线(线条上没有边线)只在x轴上显示每小时(24小时)?
我在想ggplot2的东西,但是我仍然在学习R基础知识。
ggplot
包打印数据,并使用 scale_x_discrete()
选项来指定 breaks
。 library(ggplot2)
is_full_time <-gppl(':00',temp $ Time)
ggplot(temp,aes(x = Time,y = Temp1,group = 1))+ geom_line()+ scale_x_discrete(breaks = temp $ Time [is_full_time])
I'd like to create two temperature curves in one plot. My Dataframe looks like this:
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)
How can I get clean curves (no edges on the lines like a linechart) by only showing each hour (24 hours) on the x-axis? Im thinking about something with ggplot2 but I'm still learning R basics.
解决方案
If you want to plot all values but only have full hours as x-axis labels you can plot the data with the ggplot
package and use the scale_x_discrete()
option to specify the 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
这篇关于温度曲线在R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文