Config Router

  • Google Sheets
  • CCNA Online training
    • CCNA
  • CISCO Lab Guides
    • CCNA Security Lab Manual With Solutions
    • CCNP Route Lab Manual with Solutions
    • CCNP Switch Lab Manual with Solutions
  • Juniper
  • Linux
  • DevOps Tutorials
  • Python Array
You are here: Home / ggplot geom_text font size control

ggplot geom_text font size control

August 23, 2021 by James Palmer

Here are a few options for changing text / label sizes
library(ggplot2)

# Example data using mtcars

a <- aggregate(mpg ~ vs + am , mtcars, function(i) round(mean(i))) p <- ggplot(mtcars, aes(factor(vs), y=mpg, fill=factor(am))) + geom_bar(stat="identity",position="dodge") + geom_text(data = a, aes(label = mpg), position = position_dodge(width=0.9), size=20) The size in the geom_text changes the size of the geom_text labels. p <- p + theme(axis.text = element_text(size = 15)) # changes axis labels p <- p + theme(axis.title = element_text(size = 25)) # change axis titles p <- p + theme(text = element_text(size = 10)) # this will change all text size # (except geom_text) For this And why size of 10 in geom_text() is different from that in theme(text=element_text()) ? Yes, they are different. I did a quick manual check and they appear to be in the ratio of ~ (14/5) for geom_text sizes to theme sizes. So a horrible fix for uniform sizes is to scale by this ratio geom.text.size = 7 theme.size = (14/5) * geom.text.size ggplot(mtcars, aes(factor(vs), y=mpg, fill=factor(am))) + geom_bar(stat="identity",position="dodge") + geom_text(data = a, aes(label = mpg), position = position_dodge(width=0.9), size=geom.text.size) + theme(axis.text = element_text(size = theme.size, colour="black")) This of course doesn't explain why? and is a pita (and i assume there is a more sensible way to do this)

Related

Filed Under: Uncategorized

Recent Posts

  • How do I give user access to Jenkins?
  • What is docker volume command?
  • What is the date format in Unix?
  • What is the difference between ARG and ENV Docker?
  • What is rsync command Linux?
  • How to Add Music to Snapchat 2021 Android? | How to Search, Add, Share Songs on Snapchat Story?
  • How to Enable Snapchat Notifications for Android & iPhone? | Steps to Turn on Snapchat Bitmoji Notification
  • Easy Methods to Fix Snapchat Camera Not Working Black Screen Issue | Reasons & Troubleshooting Tips to Solve Snapchat Camera Problems
  • Detailed Procedure for How to Update Snapchat on iOS 14 for Free
  • What is Snapchat Spotlight Feature? How to Make a Spotlight on Snapchat?
  • Snapchat Hack Tutorial 2021: Can I hack a Snapchat Account without them knowing?

Copyright © 2025 · News Pro Theme on Genesis Framework · WordPress · Log in