Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201919

How to use superscript in facet_wrap labels in R?

$
0
0

In my facet_label i would like to use superscript such as in Figure below 3 should be superscript to m. Also i would like to assign degree sign with C in the temperature subplots. Also, i would like to see zero horizontal line only in temperature plots but not in streamflow and precipitation plots. Below is my code so far and i would appreciate any help.

library(tidyverse)
MonthlyData = data.frame(Month = 1:12, A = runif(12, 1,40), B = runif(12,-25,15), C = runif(12,-15,25), D = runif(12,1,75))
PlotData = gather(data = MonthlyData, key = "Variable", value = "Value", -Month)
PlotData$Variable = factor(PlotData$Variable, labels = c("Streamflow (m3/sec)", "Max temperature (oC)", "Min temperature (oC)", "Precipitation (mm)"))

ggplot(transform(PlotData, Variable = factor(Variable, levels = c("Streamflow (m3/sec)", "Precipitation (mm)", "Max temperature (oC)", "Min temperature (oC)"))), aes(x = Month, y = Value))+
  geom_bar(stat = "identity", width = 0.5) + facet_wrap(~Variable, nrow = 4, scales = "free_y")+ 
  geom_hline(yintercept = 0)+ aes(fill = as.factor(Variable))+
  scale_x_continuous(breaks = c(1:12), labels = c("Jan", "Feb", "Mar","Apr", "May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"))+
  theme_bw()

Here is my plot based on the example data

enter image description here


Viewing all articles
Browse latest Browse all 201919

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>