[R] Removing a data subset

David Doyle kydaviddoyle at gmail.com
Wed Nov 29 22:07:34 CET 2017

Say I have a dataset that looks like

Location    Year      GW_Elv
MW01        1999       546.63
MW02        1999       474.21
MW03        1999       471.94
MW04        1999        466.80
MW01        2000        545.90
MW02        2000        546.10

The whole dataset is at http://doylesdartden.com/ExampleData.csv
and I use the code below to do the graph but I want to do it without MW01.
How can I remove MW01??

I'm sure I can do it by SubSeting but I can not figure out how to do it.

Thank you



MyData <- read.csv("http://doylesdartden.com/ExampleData.csv", header=TRUE,

#Sets whic are detections and nondetects
MyData$Detections <- ifelse(MyData$D_GW_Elv ==1, "Detected", "NonDetect")

#Removes the NAs
MyDataWONA <- MyData[!is.na(MyData$Detections), ]

#does the plot
p <- ggplot(data = MyDataWONA, aes(x=Year, y=GW_Elv , col=Detections)) +
  geom_point(aes(shape=Detections)) +

  ##sets the colors
  scale_colour_manual(values=c("black","red")) + #scale_y_log10() +

  #location of the legend
  theme(legend.position=c("right")) +

  #sets the line color, type and size
  geom_line(colour="black", linetype="dotted", size=0.5) +
  ylab("Elevation Feet Mean Sea Level")

## does the graph using the Location IDs as the different Locations.
p + facet_grid(Location ~ .)

	[[alternative HTML version deleted]]

More information about the R-help mailing list