I have the following data set in a csv file, and would like to adjust the size/face of the y axis label, but the command does not work (it only works to change the label, so I can change 'mg/kg' to anything else):
facet group oxidation value
nZVI DW Fe(II) 0.319152
nZVI RW Fe(II) 5.0832
nZVI DW Fe(III) 8.39736
nZVI RW Fe(III) 9.3168
nZVI-BC DW Fe(II) 0.596304
nZVI-BC RW Fe(II) 7.09764
nZVI-BC DW Fe(III) 14.1696
nZVI-BC RW Fe(III) 9.88236
Fe/FeS-BC DW Fe(II) 0.382658
Fe/FeS-BC RW Fe(II) 42.687
Fe/FeS-BC DW Fe(III) 5.4791
Fe/FeS-BC RW Fe(III) 4.743
BC DW Fe(II) 2.5047
BC RW Fe(II) 17.76875
BC DW Fe(III) 20.2653
BC RW Fe(III) 10.66125
Control DW Fe(II) 1.457266
Control RW Fe(II) 20.992
Control DW Fe(III) 24.47792
Control RW Fe(III) 11.008
and the code I am using:
e.data <- read_csv('Grouped stack bars.csv')
e.data <- mutate(e.data,
facet = parse_factor(facet,
levels = c('Control',
'nZVI',
'nZVI-BC',
'Fe/FeS-BC',
'BC')))
ggplot(e.data,
aes(x = group,
y = value,
fill = oxidation))
geom_bar(stat = "identity",
position = "stack")
facet_grid(~ facet)
theme_bw()
labs(y = paste('mg/kg'), size = 33, face = 'bold',
x = NULL)
CodePudding user response:
The labs
function can control the text that will appear in various important plot parts, like the title
, subtitle
, caption
, and axis labels for x
and y
. But it doesn't do any formatting. For that you want the theme()
function. Look up ?theme
to see all the options (many!). You probably want theme(axis.title.y = element_text(size = 33, face = "bold"))
.
PS -- btw, it's important to put any theme(...)
specifications after the theme_bw()
line. theme_bw()
is essentially a shortcut for a long list of theme(...)
specifications, so if you want to overwrite those with customizations, those changes should come afterwards, otherwise it'll just go with the last specifications received, ie the defaults in theme_bw()
.