1

strange enough, my code was halfway working but refuses to do so now, after trying to insert some superscripts in the y-axes (I have two) titles. I managed at least to get the superscripts working in the left y-axis (see boxplot attached). Now I neither get superscripts with trying bracketed and "" solutions, nor can I plot it again.

Here's the code, with superscript location (or issue) in the "scale_y_continuous" line:

coeff<-10
cbp1 <- c("#999999", "#E69F00", "#56B4E9", "#009E73",
          "#F0E442", "#0072B2", "#D55E00", "#CC79A7")
d7$Week <- as.factor(d7$Week) 

ms.chl2<- ggplot(d7, aes(x=Product, y=Mean, fill=Week))+
  labs(title="Yields per harvest frequency", x="", y="t/ha/yr", fill="Week")+ 
  theme(plot.title = element_text(size=25, margin=margin(t=20, b=20)))+
  geom_bar(position = position_stack(reverse = TRUE),stat="identity", colour="black")+
  facet_grid(~Cuts)+
  theme_bw()+
  scale_y_continuous(expression(Biomass~Yield~(t~ha^-1~yr^-1)), sec.axis = sec_axis(~.*coeff, expression(Protein~/~TP~Yield~(dt~ha^-1~yr^-1))))+
  scale_fill_manual( values=cbp1, aesthetics = "fill", breaks = waiver())+
  theme(axis.title.y = element_text(color = "black", face = "bold", size = 14),
    axis.title.y.right = element_text(color = "blue", face = "bold", size = 14))

ms.chl2 + geom_errorbar(aes(ymin=Mean2-SD, ymax=Mean2+SD), size=0.5,width=0.45) + facet_grid(~Cuts)

Probably a simple solution - but I can't figure it out

Cheers, Claudia

Edit, sample input (my dataframe d7):

Cuts Week      Product       Mean       Mean2      SD
2     24       Biomass       6.500000   6.500000   2.30079696
2     37       Biomass       6.327500   12.827500  1.86326550
4     20       Biomass       1.790000   1.790000   0.64658075
4     24       Biomass       2.847500   4.637500   0.90698677
4     37       Biomass       8.072500   12.710000  4.51450533
4     43       Biomass       2.395000   15.105000  1.52790706
2     24       Protein       7.539058   7.539058   0.20528988
2     37       Protein       11.238639  18.777697  0.20308174
4     20       Protein       3.350810   3.350810   0.11329719
4     24       Protein       4.526551   7.877360   0.12157274
4     37       Protein       11.012470  18.889830  0.58791330
4     43       Protein       12.623990  31.513820  0.13700000
2     24       TP (B1 + B2)  4.327170   4.327170   0.13155455
2     37       TP (B1 + B2)  4.643391   8.970561   0.12580438
4     20       TP (B1 + B2)  1.545472   1.545472   0.04790458
4     24       TP (B1 + B2)  3.075384   4.620856   0.07924300
4     37       TP (B1 + B2)  4.857043   9.477899   0.27978719
4     43       TP (B1 + B2)  2.536269   12.014168  0.15639603

Claudia
  • 53
  • 4
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Are you sure you aren't getting errors? Your `expression()` doesn't seem like a valid expression. Not sure what you are trying to do there. – MrFlick Apr 29 '20 at 05:14
  • sample input included – Claudia Apr 29 '20 at 07:46

0 Answers0