I'm a beginner in R, so maybe it sounds simple but I'm looking to stack two
bar plot
.
For example, for the city BIRR, I have two graphs: one with the precipitations, the other with the temperatures.
What I am trying to do is that for each month 04/2004, I would like to have the barplot stacks temperatures and the barplot stacks precipitation.
I put you my dataset below:
#TEMP_BIR
"SOUNAME" "year_month" "temperature_type" "temperature_value"
"1" "BIRR" "2004-04" "VERY_COLD" 0
"2" "BIRR" "2004-05" "VERY_COLD" 0
"3" "BIRR" "2004-06" "VERY_COLD" 0
"4" "BIRR" "2004-07" "VERY_COLD" 0
"5" "BIRR" "2004-04" "MEDIUM" 28
"6" "BIRR" "2004-05" "MEDIUM" 29
"7" "BIRR" "2004-06" "MEDIUM" 19
"8" "BIRR" "2004-07" "MEDIUM" 25
"9" "BIRR" "2004-04" "HOT" 0
"10" "BIRR" "2004-05" "HOT" 2
"11" "BIRR" "2004-06" "HOT" 11
"12" "BIRR" "2004-07" "HOT" 6
"13" "BIRR" "2004-04" "COLD" 2
"14" "BIRR" "2004-05" "COLD" 0
"15" "BIRR" "2004-06" "COLD" 0
"16" "BIRR" "2004-07" "COLD" 0
# Temp_prec_birr
"SOUNAME" "year_month" "precipitation_type" "precipitation_value"
"BIRR" "2004-04" "NONE" "11"
"BIRR" "2004-05" "NONE" "20"
"BIRR" "2004-06" "NONE" "11"
"BIRR" "2004-07" "NONE" "10"
"BIRR" "2004-04" "HEAVY" "2"
"BIRR" "2004-05" "HEAVY" "1"
"BIRR" "2004-06" "HEAVY" "1"
"BIRR" "2004-07" "HEAVY" "1"
"BIRR" "2004-04" "LIGHT" "15"
"BIRR" "2004-05" "LIGHT" "7"
"BIRR" "2004-06" "LIGHT" "16"
"BIRR" "2004-07" "LIGHT" "18"
"BIRR" "2004-04" "MEDIUM" "2"
"BIRR" "2004-05" "MEDIUM" "3"
"BIRR" "2004-06" "MEDIUM" "2"
"BIRR" "2004-07" "MEDIUM" "2"
#I put you my code below:
ggplot(data = TEMP_PREC_BIRR, aes(x = TEMP_PREC_BIRR$year_month,
y = TEMP_PREC_BIRR$precipitation_value,
fill = TEMP_PREC_BIRR$precipitation_type)) +
geom_bar(aes (width = .2), stat = "identity") +
xlab("date") + ylab ("Number of days of precipitation") +
ggtitle("Precipitation per month - BIRR") + labs(fill = "Frequency")
ggplot(data = TEMP_BIRR, aes(x = TEMP_BIRR$year_month,
y = TEMP_BIRR$temperature_value,
fill = TEMP_BIRR$temperature_type)) +
geom_bar(aes(width = .2), stat = "identity") +
xlab("date") + ylab("Number of days of temperature") +
ggtitle("Temperature per month - BIRR") + labs(fill = "Frequency")