简体   繁体   中英

How do I change the text font, size and colour of all the different texts in the R package, Likert?

At the moment, there is only features in place to change the font of the percentages, but I would like to change the font, size and colour of all text in the Likert package's bar plot. How would I go about doing this?

You do it pretty much how you would any ggplot : by adding theme() options. (At least, how you'd fine-tune things anyway.)

Using the example data from ?likert

library("likert")
data(pisaitems)
items29 <- pisaitems[,substr(names(pisaitems), 1,5) == 'ST25Q']
names(items29) <- c("Magazines", "Comic books", "Fiction",
                    "Non-fiction books", "Newspapers")
l29 <- likert(items29)
summary(l29)

p1 <- plot(l29) # assign the plot to an object

# modify some stuff
p1 + theme(text = element_text(size = rel(6), colour = "red"),
           axis.text.y = element_text(colour = "blue",
                                      family = "Courier"))

In general, you can look at the return of a theme call, eg theme_bw() to see all the things that can be modified this way. Anything that is set in the plot.likert code will (eg the y axis text colour) will need to be explicitly modified, it won't inherit from the more general text . If it's mostly text you're modifying, ?element_text will probably be helpful.

Also note that if you're using RStudio setting the font family may not change the plot in the plot window, but it will work if you export the plot as a PDF. (At least for me, on Windows.)

If you want to change the text that is part of the plot (set by geom_text ), you'll probably need to actually hack the function. It's all on github , so just make your own fork of the package.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM