I am trying to plot minimum and maximum temperatures, and with a normal dot plot (using pch = 16) it looks normal, but when I change the plot type to line (using type="l"), it adds a line that seems to connect the first and last values.
Is there a way to get rid of the straight line that connects the first and last value & why is that happening?
Here's the Data Structure:
> y
Source: local data frame [365 x 6]
Groups: Month [12]
Month Day Tmp_min MonthDay_min Tmp_max
<fctr> <chr> <dbl> <chr> <dbl>
1 07 01 62 07/01 69
2 07 02 61 07/02 67
3 07 03 60 07/03 66
4 07 04 60 07/04 64
5 07 05 60 07/05 65
6 07 06 61 07/06 66
7 07 07 61 07/07 67
8 07 08 61 07/08 69
9 07 09 61 07/09 70
10 07 10 62 07/10 69
Here's the plot code:
plot(Tmp_min ~ as.Date(y$MonthDay_min, format='%m/%d'), data=y, type="l",
col="turquoise", ylab="Temperature (F)",
main=paste("Minimum and Maximum Daily Temperatures"), xlab="Month",
ylim=c(0,100))
points(Tmp_max ~ as.Date(y$MonthDay_min, format='%m/%d'), data=y, type="l",
col="orange", ylim=c(0,100))
This issue is likely due to missing year...try adding a year.
MonthDay_min <- c('07/01', '07/02', '07/03', '07/04', '06/30')
Tmp_min <- c(62, 70, 61, 58, 100)
Tmp_max <- c(69, 78, 66, 64, 105)
y <- data.frame(MonthDay_min, Tmp_min, Tmp_max)
year <- c(2016, 2016, 2016, 2016, 2017)
y$MonthDay_min <- paste(y$MonthDay_min, '/', year, sep = "")
plot(Tmp_min ~ as.Date(y$MonthDay_min, format='%m/%d/%Y'), data=y, type="l",
col="turquoise", ylab="Temperature (F)",
main=paste("Minimum and Maximum Daily Temperatures"), xlab="Month",
ylim=c(0,100))
points(Tmp_max ~ as.Date(y$MonthDay_min, format='%m/%d/%Y'), data=y, type="l",
col="orange", ylim=c(0,100))