I am trying to make a graph showing the average temp in Australia from 1950 to 2000. My dataset contains a "Country" table which contains Australia but also other countries as well. The dataset also includes years and average temp for every country. How would I go about excluding all the other data to make a graph just for Australia?
CodePudding user response:
You just need to subset your data so that it only contains observations about Australia. I can't see the details of your dataset from your picture, but let's assume that your dataset is called d
and the column of d
detailing which country that observation is about is called country
. Then you could do the following using base r:
d_aus <- d[d$country == "Australia", ]
Or using dplyr
you could do:
library(dplyr)
d_aus <- d %>%
filter(country == "Australia")
Then d_aus
would be the dataset containing only the observations about Australia (in which `d$country == "Australia"), which you could use to make your graph.
CodePudding user response:
This should make the job. Alternatively, change the names of the columns to those of yours.
library("ggplot2")
library("dplyr")
data %>% filter(Country == "Australia" & Year %in% (1950:2000)) %>% ggplot(.,aes(x=Year,y=Temp)) geom_point()