1

Please consider the following plot. I have maintained details of structure, packages, etc, as I am not sure what is causing the issue. I am sure this is quite simple, but I am unable to make it work.

require(reshape2)
require(ggplot2)
require(dplyr)
require(tidyr)

    #setting up labels -- find out why italics expression isn't working??
Fig.labels<-c(expression(paste(italic("C. ret"), "-0d")),
expression(paste(italic("C. ret"), "-4d")),
expression(paste(italic("C. ret"), "-14d")),
expression(paste(italic("M. pan"), "-4d")),
expression(paste(italic("M. pan"), "-14d")))


A1_0d_ret<-rnorm(1:100,20)
A2_4d_ret<-rnorm(1:100,18)
A3_14d_ret<-rnorm(1:100,30)
A4_4d_pan<-rnorm(1:100,7)
A5_14d_pan<-rnorm(1:100,40)

data<-data.frame(A1_0d_ret,
A2_4d_ret,
A3_14d_ret,
A4_4d_pan,
A5_14d_pan)

long.data<-melt(data)

long.data_<-separate(data = long.data, col = variable, into = c("group", "treatment", "species"), sep = "_", remove=FALSE)

ggplot(long.data_, aes(x=treatment, y=log(value), group=variable))+
geom_boxplot(outlier.shape = NA, width=0.2 )+
scale_x_discrete("Never mind weird plot", labels=Fig.labels)+
theme_classic()

Note loack of italics on legend

I wish to mix normal fonts with italics. Why aren't italics working on the labels from expression()? I have seen so many similar working examples.

Edit: this is on RStudio 1.1.456

Scientist
  • 1,061
  • 2
  • 13
  • 30
  • 1
    When I run your code I get the term "C.ret" in italics and everything else without italics. Are you getting something else? – aosmith Aug 20 '18 at 17:39
  • 1
    could you please specify your problem? I get a correct mixture of italics and normal fonts in the x axis, like your describe as intended output. – mischva11 Aug 20 '18 at 17:40
  • Thanks for testing. It does not show Italics from my side!.. I am editing to add a picture, plus R specifications I am using!.. – Scientist Aug 20 '18 at 17:43
  • 1
    i also uploaded your plot [on imgur](https://i.stack.imgur.com/92E0F.png), i changed for better visualization the first x tick to normal font. So code seems fine for me, let's see if we can find something else. Also you could try to save the picture first on hardware. Maybe it's a visualization problem in rstudio/r – mischva11 Aug 20 '18 at 17:48
  • @mischva11 Indeed this looks like a version issue!.. I will see what I can do. Very unfortunate... Thanks! – Scientist Aug 20 '18 at 17:54
  • 1
    i posted this as answer with a small summary, i hope your problem gets solved by updating your software. – mischva11 Aug 20 '18 at 18:02

1 Answers1

1

Since your code seems fine by some users, as seen in this created plot by your code (mention that the first tick is normal font for visualization purpose) you can try update your packages your plot

updating single packages

for the librarys like ggplot2 you can use the update.packages() function (documentation)

updating r

for this answer it's more easy to link an old stackoverflow question

You have to download R from the website and install it again manually, sadly there is no option to do this in RStudio. For more help and a more detailed walktrough check out the old post.

mischva11
  • 2,811
  • 3
  • 18
  • 34
  • Would you also please know whether the following related question (almost same code of mine) is due to a RStudio version issue? https://stackoverflow.com/questions/51935753/specifying-ggplot2-box-plot-width-for-a-single-boxplot-lane – Scientist Aug 20 '18 at 18:06
  • Unfortunately I just followed instructions to reinstall R from inside RStudio, reinstalled all relevant packages, and still italics are not working. I will try shifting to another computer. – Scientist Aug 20 '18 at 18:20
  • @Scientist alright i'm running out of ideas. I'm running on linux, but that shouldn't make any difference. You could also check with `sessionInfo()` what your versions are. Maybe comparing them with mine gives you some information [link](https://i.stack.imgur.com/gb8kr.png) – mischva11 Aug 20 '18 at 18:31
  • Mine are R version 3.5.1 (2018-07-02) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: macOS Sierra 10.12.5 – Scientist Aug 20 '18 at 18:51
  • 1
    @Scientist this could maybe a hint, apple often has problems with italic fonts, maybe there is a issue. You could try out if the problem occours with different fonts – mischva11 Aug 20 '18 at 19:00