Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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!

>Solution :

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()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading