Home > database >  How to make exploratory plots using only certain rows in a column
How to make exploratory plots using only certain rows in a column

Time:12-02

I am making some exploratory plots to analyze zone M. I need one that plots Distance over time and another with Distance vs. MHT.

Here is what I have so far:

library(ggplot2)

ggplot(datmarsh, aes(x=Year, y=Distance))   geom_point()
ggplot(datmarsh, aes(x=MHT, y=Distance))   geom_point()

What I'm struggling with is specifying only zone "M" in each of these graphs.

Here is a sample of what my data looks like:

Year    Distance    MHT Zone
1975    253.1875    933 M
1976    229.75      877 M
1977    243.8125    963 M
1978    243.8125    957 M
1975    103.5       933 P
1976    150.375     877 P
1977    117.5625    963 P
1978    131.625     957 P
1979    145.6875    967 P
1975    234.5       933 PP
1976    314.1875    877 PP
1977    248.5625    963 PP
1978    272         957 PP
1979    290.75      967 PP

Thanks!

CodePudding user response:

dplyr::filter() will let you do what you need. However, this has probably been answered elsewhere a few times, so do try searching!

library(dplyr)
library(ggplot2)
library(magrittr)

datmarsh %>%
    filter(Zone == "M") %>%
    ggplot(aes(x=Year, y=Distance))   
    geom_point()

datmarsh %>%
    filter(Zone == "M") %>%
    ggplot(daes(x=MHT, y=Distance))  
    geom_point()
  • Related