Reputation: 137
I'm trying to rename the columns in my bar graph from "nCO2" and "pCO2" to "-CO2" and "+CO2". I decided to do it at the end of the plot construction rather than renaming the elements at the beginning, since the + and - interfered with the data transformations. How can I rename these columns after the construction of my bar plot?
structure(list(CO2_stacks = c("nCO2", "nCO2", "nCO2", "nCO2",
"nCO2", "nCO2", "pCO2", "pCO2", "pCO2", "pCO2", "pCO2", "pCO2"
), count = c(3.3, 3.2, 3, 3.5, 3.3, 3.2, 4, 3.9, 4.2, 4.1, 4.3,
4)), class = "data.frame", row.names = c(NA, -12L))
Plotting:
ggplot(stackoverflow, mapping = aes(CO2_stacks, count)) + geom_boxplot()
Upvotes: 1
Views: 1570
Reputation: 39613
Try this:
library(ggplot2)
ggplot(stackoverflow, mapping = aes(CO2_stacks, count)) +
geom_boxplot()+
scale_x_discrete(labels= c("nCO2"="-CO2","pCO2"="+CO2"))
Output:
Upvotes: 3