简体   繁体   中英

Add Min/Max Values as Horizontal Lines in R Plot

I have made a line chart in R and now I want to add a two more lines of min and max values that are already exist in seperate column in same csv file. Here is my code that i used

plot(MedTemp$Loggers.distance, MedTemp$Temperature..C...2017., xaxt = "n", xlab = "",ylab = "", main = "Median Temperature 2017", col.main = "darkred", col = "blue", pch = 19, ylim = c(-5,25), fill = "blue", type = "o")
axis(1, at = c(0, 4698.91, 5424.74, 8731.54, 10103.81, 14361.29 ), cex.axis = 0.55, las = 2)
lines(MedTemp$Loggers.distance[order(MedTemp$Loggers.distance)], MedTemp$Temperature..C...2017.[order(MedTemp$Loggers.distance)], xlim = range(MedTemp$Loggers.distance), ylim = range(MedTemp$Temperature..C...2017.), pch = 16, col = "firebrick", lwd = 1.5)
text(MedTemp$Temperature..C...2017.~ MedTemp$Loggers.distance, labels = c(" ","Orchar\nHill","Roland\nRoad","Gilligan\nRoad","Wetaskiwin"," "), cex = 0.5, font = 2, pos = 1, srt = 0)
text(MedTemp$Temperature..C...2017.~ MedTemp$Loggers.distance, labels = c("Rice\nRoad"," "," "," "," "," "), cex = 0.5, font = 2, pos = 1, srt = 0)
text(MedTemp$Temperature..C...2017.~ MedTemp$Loggers.distance, labels = c(" "," "," "," "," ","Decew\nRoad"), cex = 0.5, font = 2, pos = 1, srt = 0)
mtext(1, text = "Thermal Loggers Chainage Distance(m)", line = 3, cex = 0.9)
mtext(2, text = "Temperature (C)", line = 3, cex = 0.9)

Here is my data: Excel的SS

Here is my chart: 情节SS

Any help would be appreciated.

The command you're looking for is abline . something along the lines of

abline(h = c(min_value, max_value))

You can add similar instructions for color, linetype, linewidth to the function as did with other plot functions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM