Trend Analysis of two data sets

Hi all,
I have two datasets site1.csv and site2.csv. This data is about coal produced in the sites from 2005 to 2020. I want to plot the total coal production in these two sites on the same plot using ggplot. I can plot one site but unable to plot the second one. How can I get this done?

Sample Datasets:

site1.csv:

Date                 Coal(in mill tons)
Jan 2005               12.0
Feb 2005               12.2
.                               .
.                               .
.                               .
.                               .
.                               .
site2.csv
Date                 Coal(in mill tons)
Jan 2005               12.0
Feb 2005               12.2
.                               .
.                               .
.                               .
.                               .
.                               .

Thanks in advance.

site1 <-data.frame(datenum=c(1,2,3,4),
                   vals = c(1.1,1.2,1.3,1.3))

site2 <-data.frame(datenum=c(1,2,3,4),
                   vals = c(1.3,1.2,1.2,1.1))


combined <- union_all(site1 %>% mutate(grp="site1"),
                      site2 %>% mutate(grp="site2"))
ggplot(data=combined,aes(x=datenum,y=vals,fill=grp)) + 
  geom_col(position = position_dodge())

ggplot(data=combined,aes(x=datenum,y=vals,color=grp)) + 
  geom_line()

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.