How can I Plotting temporal data of 3 different areas?

77 views Asked by At

I would like to plot my temporal data but for some reason I'm not getting to plot clearly. I use this function:

plot(temperature~month*area, data=mydata)

But this function don't separate the areas.

My example is:

            area    month   temperature
              d1    november    18,723
              d1    november    16,963
              d1    november    22,753
              d1    november    30,495
              d1    november    26,818
              d1    november    22,944
              i1    november    18,485
              i1    november    17,368
              i1    november    16,844
              i1    november    24,171
              i1    november    28,072
              i1    november    28,766
              i1    november    25,744
              i1    november    22,920
              c1    november    17,272
              c1    november    16,225
              c1    november    16,058
              c1    november    22,920
              c1    november    28,642
              c1    november    26,256
              d1    december    17,558
              d1    december    28,468
              d1    december    21,318
              i1    december    21,246
              i1    december    20,103
              c1    december    27,776
              c1    december    21,652
              c1    december    19,793
              c1    december    18,628
              c1    december    17,796
1

There are 1 answers

2
rbroberg On

Your data is a bit odd. You have only two dates. Each of your three areas have multiple temps for those dates. It would make little sense to use a line plot. The following code provides a scatter plot grouped by area. It uses the library ggplot2 to do plot by group.

dat <- read.table(
  header=TRUE, text='area day_month_year temperature 
d1 09_11_2013 18,723 
d1 09_11_2013 17,558 
d1 09_11_2013 16,963 
d1 09_11_2013 22,753 
d1 09_11_2013 28,468 
d1 09_11_2013 30,495 
d1 09_11_2013 26,818 
d1 09_11_2013 22,944 
d1 10_11_2013 21,318 
i1 09_11_2013 18,485 
i1 09_11_2013 17,368 
i1 09_11_2013 16,844 
i1 09_11_2013 24,171 
i1 09_11_2013 28,072 
i1 09_11_2013 28,766 
i1 09_11_2013 25,744 
i1 09_11_2013 22,920 
i1 10_11_2013 21,246 
i1 10_11_2013 20,103 
c1 09_11_2013 17,272 
c1 09_11_2013 16,225 
c1 09_11_2013 16,058 
c1 09_11_2013 22,920 
c1 09_11_2013 27,776 
c1 09_11_2013 28,642 
c1 09_11_2013 26,256 
c1 09_11_2013 21,652 
c1 10_11_2013 19,793 
c1 10_11_2013 18,628 
c1 10_11_2013 17,796')

# convert temp to numeric data
dat$temp=as.numeric(gsub(',','.',dat$temp))

# convert day_month_year to date and add to dataframe
dat$date=as.Date(dat$day_month_year,"%d_%m_%Y")

# scatter plot by group
library(ggplot2)
ggplot(dat, aes(x=date, y=temp, colour=area, group=area)) + geom_point()

I note that you have changed the format of the dates in your data. This solution uses your original format. If you want to continue to use the new format with the name of the month, you will need to modify the as.Date cast.