如何仅使用列中的某些行制作探索性图

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

我正在制作一些探索性绘图来分析 M 区。我需要一个绘制随时间变化的距离,另一个绘制距离与 MHT。

这是我目前的情况:

library(ggplot2)

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

我遇到的困难是在每个图表中仅指定区域“M”。

这是我的数据示例:

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

谢谢!

dplyr::filter() 会让你做你需要的。但是,这可能已经在其他地方回答过几次了,所以请尝试搜索!

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()