r - 在 x 和 y 轴上显示数据点的位置
问题描述
我想在 y 和 x 轴上显示特定数据点的位置。基本上,我知道测量前的起点(12:00 或 160:00),我想识别曲线上的数据点并标记它。有什么建议么?
样本数据:
df<-structure(list(time = c("04:00", "04:15", "04:30", "04:45", "05:00",
"05:15", "05:30", "05:45", "06:00", "06:15", "06:30", "06:45",
"07:00", "07:15", "07:30", "07:45", "08:00", "08:15", "08:30",
"08:45", "09:00", "09:15", "09:30", "09:45", "10:00", "10:15",
"10:30", "10:45", "11:00", "11:15", "11:30", "11:45", "12:00",
"12:15", "12:30", "12:45", "13:00", "13:15", "13:30", "13:45",
"14:00", "14:15", "14:30", "14:45", "15:00", "15:15", "15:30",
"15:45", "16:00", "16:15", "16:30", "16:45", "17:00", "17:15",
"17:30", "17:45", "18:00", "18:15", "18:30", "18:45", "19:00",
"19:15", "19:30", "19:45", "20:00", "20:15", "20:30", "20:45",
"21:00", "21:15", "21:30", "21:45", "22:00", "22:15", "22:30",
"22:45", "23:00", "23:15", "23:30", "23:45", "00:00", "00:15",
"00:30", "00:45", "01:00", "01:15", "01:30", "01:45", "02:00",
"02:15", "02:30", "02:45", "03:00", "03:15", "03:30", "03:45"
), index = 1:96, variable = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "value", class = "factor"),
value = c(0, 0.00120336943441637, 0.00401123144805455, 0.00481347773766546,
0.0116325711993582, 0.0104292017649418, 0.0236662655435219,
0.0284797432811873, 0.0709987966305656, 0.0770156438026474,
0.0882470918572002, 0.0918572001604493, 0.201363818692339,
0.219013237063779, 0.281989570798235, 0.298435619735259,
0.503409546730846, 0.555956678700361, 0.67428800641797, 0.707180104292018,
0.8896911351785, 0.922583233052547, 0.935018050541516, 0.936221419975933,
0.963096670677898, 0.974729241877256, 0.985960689931809,
0.984757320497393, 0.984757320497393, 0.994785399117529,
1, 0.997994384275973, 0.919775371038909, 0.902527075812274,
0.860409145607702, 0.854793421580425, 0.756117127958283,
0.768953068592058, 0.837545126353791, 0.847172081829122,
0.944243882872042, 0.963497793822704, 0.965503409546731,
0.967107902125953, 0.957079823505816, 0.969915764139591,
0.9558764540714, 0.953469715202567, 0.890894504612916, 0.882872041716807,
0.8235058162856, 0.805054151624549, 0.661452065784196, 0.631768953068592,
0.549538708383474, 0.51544324107501, 0.300842358604091, 0.277978339350181,
0.235058162855997, 0.214199759326113, 0.143602085840353,
0.139590854392298, 0.129161652627357, 0.127557160048135,
0.0946650621740874, 0.0934616927396711, 0.0886482150020056,
0.0834336141195347, 0.0709987966305656, 0.0722021660649819,
0.0705976734857601, 0.0701965503409547, 0.0605695948656237,
0.0605695948656237, 0.0573606097071801, 0.0561572402727637,
0.0389089450461292, 0.036101083032491, 0.0344965904532692,
0.0348977135980746, 0.0260730044123546, 0.0280786201363819,
0.0260730044123546, 0.0260730044123546, 0.0212595266746891,
0.0208584035298837, 0.0164460489370237, 0.0156438026474128,
0.00922583233052547, 0.00882470918572002, 0.00842358604091456,
0.00882470918572002, 0.00240673886883273, 0.00200561572402728,
0.00200561572402728, 0.00200561572402728)), class = "data.frame", row.names = c(NA,
-96L))
到目前为止的代码:
plot<-ggplot(df, aes(x=time, y=value, group=variable)) + geom_line()+labs(x="Time (hours)", y="Normalized values", title="")+theme_bw()
plot+ theme(axis.text.x = element_text(angle = , hjust = 1,family="Times", face="bold", size=12), axis.text.y = element_text(family="Times", face="bold", size=12),strip.text = element_text(size=6, face="bold")) +theme(plot.title = element_text(hjust = 0.5))+scale_x_discrete(limits = c( "04:00", "07:00", "08:00","08:10" , "12:00", "16:00", "20:00", "22:00", "00:00","04:00"), expand=c(-1,1)) + scale_y_continuous(expand = c(-0, 0))
解决方案
您应该能够通过将以下代码附加到您的绘图来获得标记的点和线:
geom_segment(x = 0,
xend = "12:00",
y = 0.919775371, yend = max(
0.919775371), linetype = 2) + geom_segment(x = "12:00",
xend = "12:00",
y = 0, yend = max(
0.919775371), linetype = 2) +
geom_segment(x = "16:00",
xend = "16:00",
y = 0, yend = max(
0.890894505), linetype = 2) +
geom_segment(x = 0,
xend = "16:00",
y = 0.890894505, yend = max(
0.890894505), linetype = 2) +
geom_text(x = "12:00" ,
y = 0.919775371+0.03, label = "X", check_overlap = TRUE) +
geom_text(x = "16:00" ,
y = 0.890894505+0.03, label = "Y", check_overlap = TRUE)
推荐阅读
- wordpress - 如何在wordpress PAGE中隐藏特色图片
- android - React Native Firebase Flat List 数据未在文本和图像中显示
- javascript - 来自 mysqldb 的 googlemaps api 上的多边形
- ios - 无法将 NSDictionary 保存到 FirebaseDatabase
- networking - 假接入点未显示为无线网络
- lua - 是否可以使用 HAProxy - Lua 管理用于速率限制的粘性表?
- python - 将列表中的大整数值拆分为多个列表中的较小整数
- google-chrome-extension - Chrome 扩展清单权限被阻止
- shell - NASM 不使用 /dev/stdout 作为输出
- java - 在窗口 10 64 位中开始处理时出错