Home > Enterprise >  Make X-Axis Lables, value labels and other axis and labels bold in Ggplot2
Make X-Axis Lables, value labels and other axis and labels bold in Ggplot2

Time:11-25

I work inside a research environment and I can't copy paste the code I used there, but I have enter image description here

CodePudding user response:

As I mentioned in my comment to make the value labels bold use geom_text(..., fontface = "bold") and to make the axis labels bold use axis.text.x = element_text(angle=0, hjust=.5, face = "bold").

Using a a minimal reproducible example based on the ggplot2::mpg dataset:

library(ggplot2)
library(dplyr)

# Create exmaple data
md.df2 <- mpg |>
  count(Group.1 = manufacturer, name = "value") |>
  mutate(
    variable = value >= max(value),
    Group.1 = reorder(Group.1, -value)
  )

ggplot(md.df2, aes(x = Group.1, y = value, group = variable, fill = variable))  
  geom_col(color = "black", position = "dodge")  
  geom_text(aes(label = value), vjust = -0.3, size = 4, position = position_dodge(0.9), fontface = "bold")  
  labs(x = "Species", y = "Values", title = "Order variables in barplot")  
  theme_bw()  
  theme(
    text = element_text(size = 16),
    axis.text.x = element_text(angle = 90, vjust = .5, face = "bold"),
    plot.title = element_text(hjust = 0.5),
    plot.subtitle = element_text(hjust = 0.5)
  )

CodePudding user response:

In addition to @stefan 's answer, you can also set tick length and thickness like so:

## ... plot code  
    theme(## other settings ...,
          axis.ticks = element_line(linewidth = 5),
          axis.ticks.length = unit(10, 'pt'))

However, the example "phenotype conditions" will probably remain hard to appraise, regardless of optimization on the technical level. On the conceptual level it might help to display aggregates, e. g. condition counts per Frequency and supplement a textual list of conditions (sorted alphabetically and by Frequency, or the other way round) for those readers who indeed want to look up any specific condition.

  • Related