I created the below plot but I would like the month name to be near the figure. For example “January:13.31”. Is there a way to do this
Code:
month_order <- c("January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December")
data$Month <- factor(data$Month, levels = month_order)
location_order <- c("DG2-100-0-048", "DG2-100-0-133", "DG2-100-0-210")
data$Location<- factor(data$Location , levels = location_order )
yellow_palette <- colorRampPalette(c("#FFFFCC", "#FFD700"))(12)
(ggplot(data, aes(x =energy_use_kWh , y = Location, fill=Month)) +
geom_bar(
stat = "identity",
color = "black") +
geom_text(aes(label = energy_use_kWh), position = position_stack(vjust = 0.5),hjust=0, color = "Black")+
geom_text(aes(label = Month), position = position_stack(vjust = 0.5), hjust=3,color = "Black")+
coord_flip())+
scale_fill_manual(values = yellow_palette, guide = guide_legend(title = NULL)) +
labs(x="Energy use (KWh)",y="")+
theme_bw()+
theme(axis.text.y = element_blank(), # Remove y-axis text
axis.ticks.y = element_blank())+
theme(plot.title = element_text(hjust = 0.5, face="bold", size=14, color="black"),
axis.title.x = element_text(family="Times", face="bold", size=8, color="black"),
axis.title.y = element_text(family="Times", face="bold", size=10, color="black"),
axis.text.x = element_text(hjust = 1, face="bold", size=10, color="black"),
axis.text.y = element_blank(),
legend.title = element_text(family="Times", color = "black", size = 10, face="bold"),
legend.text = element_text(family="Times", color = "black", size = 10, face="bold"),
legend.position = "bottom")# Remove y-axis tick
Plot
Data:
dput(data[,1:5])
structure(list(Location = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), levels = c("DG2-100-0-048",
"DG2-100-0-133", "DG2-100-0-210"), class = "factor"), Month = structure(c(1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L,
5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L), levels = c("January", "February", "March",
"April", "May", "June", "July", "August", "September", "October",
"November", "December"), class = "factor"), energy_use_kWh = c(13.31,
11.81, 13.15, 12.79, 11.82, 10.25, 10.59, 7.3, 6.72, 9.1, 9.55,
9.54, 12.28, 10.61, 12.3, 11.99, 11.43, 8.98, 7.78, 6.61, 6.04,
8.84, 8.55, 9.18, 3.41, 3.1, 3.54, 3.31, 3.38, 2.34, 2.29, 1.85,
1.76, 2.33, 2.55, 2.57), E_cost = c(3.99, 3.54, 3.94, 3.84, 3.55,
3.07, 3.18, 2.19, 2.02, 2.73, 2.86, 2.86, 3.68, 3.8, 3.69, 3.6,
3.43, 2.69, 2.33, 1.98, 1.81, 2.65, 2.56, 2.75, 1.02, 0.93, 1.06,
0.99, 1.01, 0.7, 0.69, 0.56, 0.53, 0.7, 0.76, 0.77), CO2_g = c(1.9,
1.9, 2, 2.1, 1.7, 1.7, 1.5, 1.1, 1.1, 1.3, 1.6, 1.3, 1.8, 1.7,
2, 1.9, 1.7, 1.5, 1.1, 1, 1, 1.3, 1.4, 1.2, 0.5, 0.5, 0.6, 0.5,
0.5, 0.4, 0.3, 0.19, 0.3, 0.3, 0.4, 0.3)), row.names = c(NA,
-36L), class = c("tbl_df", "tbl", "data.frame"))