0
votes

I have a list of temperature data which shows mean, median, SD, maximum , minimum and IQR of temperatures for different months. I wanted to generate a set of numbers using the above given values. is it possible in R ?

The smaple data :

a <- tribble( ~"Month",~"year", ~"mean", ~"SD", ~"Min", ~"Q1", ~"Med", ~"Q3", ~"Max", "July", 2018, 1.13, 0.07, 0.98, 1.09, 1.13, 1.18, 1.27, "August", 2018, 1.16, 0.08, 1.04, 1.10, 1.16, 1.22 ,1.39, "September", 2018, 1.08, 0.08, 0.97, 1.00, 1.08, 1.12, 1.29, "October", 2018, 1.16, 0.11, 0.94, 1.07, 1.16, 1.23, 1.42, "November", 2018, 1.48, 0.25, 1.02, 1.34, 1.48, 1.60, 1.93, "December", 2018, 1.82, 0.17,1.52, 1.69, 1.82, 1.92, 2.20, "January", 2019, 1.91, 0.19, 1.56, 1.76, 1.89, 2.02, 2.26, "February", 2019, 1.59, 0.17, 1.33, 1.44, 1.59, 1.77, 1.90, "March", 2019, 1.35, 0.18, 1.10, 1.20, 1.33, 1.45, 1.67, "April", 2019, 1.34, 0.10, 1.16, 1.27, 1.34, 1.41, 1.47, "May", 2019 ,1.31, 0.07, 1.14, 1.24, 1.31, 1.35, 1.43, "June", 2019, 1.31, 0.06, 1.19, 1.26, 1.31, 1.35,1.43 )

what i actually want is some boxplot like this as an output from it : -fg

1
Do you only have the summary data or do you have the raw data. In r it might be easier to do this with the raw data.Peter
This link will help you: stackoverflow.com/questions/22212885/…Peter
Have updated the formatting so it matches you desired output more closely. Please click the accept tick if this answers your question: stackoverflow.com/help/someone-answers.Peter
Have you just changed the question?. I think you are now asking a completely different question. In that case really you are asking two questions and you should pose two questions rather than edit the existing question which now seems so different that the answer no longer reflects the question.Peter
oops sorry, im new to stack overflow, i had rolled back now. thanks.i will post the second qn as a new questionSork-kal

1 Answers

1
votes

You can do this, adjusted to reflect the desired output in a bit more detail, although getting median line is a bit of a hack:

library(ggplot2)
library(tibble)


ggplot(a, aes(x = factor(Month, month.name[c(7:12, 1:6)]))) +
  geom_boxplot(aes(
    lower = Q1, 
    upper = Q3, 
    middle = Med, 
    ymin = Min, 
    ymax = Max, 
    fill = "25% - 75%"),
    stat = "identity")+
  geom_point(aes(y = mean, shape = "Mean"))+
  geom_line(aes(y = Med, colour = "Median"), size = 1)+
  guides(linetype = guide_legend(override.aes = list(linetype = 1)))+
  scale_fill_manual(values = "green")+
  scale_colour_manual(values = "black")+
  labs(y = "Energy Consumption (kWh/km)",
       x = NULL,
       fill = NULL,
       shape = NULL,
       colour = NULL)+
  theme_bw()+
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1 ),
        legend.position = c(0.9, 0.9),
        legend.justification = c(1, 1))

Created on 2020-05-31 by the reprex package (v0.3.0)