R - delete an unnecessary null row that is not associated with data

I have a simple (but very large) dataset of calculations made on different sites from April to August. There is no zero number between mid-April and July, but the line at zero extends from the earliest and last date.

enter image description here

Here is some of the data used to create the above diagram (columns are Site.ID, DATE, Visible Number):

data = structure (list (Site.ID = c (302L, 302L, 302L, 302L, 302L, 302L, 302L, 302L, 302L, 302L, 302L, 302L, 304L, 304L, 304L, 304L, 304L, 304L, 304L, 304L, 304L, 304L, 304L, 304L), DATE = (c (1L, 2L, 5L, 3L, 4L, 6L, 8L, 7L, 9L, 10L, 11L, 12L, 1L, 2L, 5L, 3L, 4L, 6L, 8L, 7L, 9L, 10L, 11L, 12L),.Label = c ( "3/21/2014", "3/27/2014", "4/17/2014", "4/28/2014", "4/8/2014", "5/13/2014", "6/17/2014", "6/6/2014", "7/10/2014", "7/22/2014", "7/29/2014", "5/5/2014",), class= "factor" ), Visible.Number = c (0L, 0L, 5L, 14L, 20L, 21L, 6L, 8L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 7L, 7L, 7L, 7L, 5L, 0L, 0L, 0L, 0L)).Names = c ( "Site.ID", "DATE", "Visible.Number" ), class= "data.frame", row.names = c (NA, -24L))

attach(data)
DATE<-as.Date(DATE,"%m/%d/%Y")
plot(data$Visible.Number~DATE, type="l", ylab="Visible Number")

, . R ? !

+4
1

. , ( ), . , " ". , lines, , for. , ggplot2

library(ggplot2)
ggplot(data, aes(x = DATE, y = Visible.Number, group = Site.ID)) + geom_line()

# if you prefer more base-like styling
ggplot(data, aes(x = DATE, y = Visible.Number, group = Site.ID)) +
  geom_line() +
  theme_bw()

:

plot(data$DATE, data$Visible.Number, type = "n",
     ylab = "Visible Number", xlab = "Date")

for(site in unique(data$Site.ID)) {
    with(subset(data, Site.ID == site),
         lines(Visible.Number ~ DATE)
    )
}

N.B. attach , , , , attach. , attach; with - "", , , .

+3

All Articles