Reputation: 5738
I have the following ggplot code that renders the box plot show below.
ggplot(comparisonData, aes(Group,score)) +
geom_boxplot(notch = TRUE, varwidth = TRUE, aes(colour = Group)) +
geom_jitter(width = 0.2, aes(colour = Group)) +
theme(legend.position = "none") +
labs(title="User Engagement Score", x="Condition", y="Score (max 140)")
In this plot I want the groups 1 and 2 on the x-axis to be renamed as "Stealth" and "Non-stealth", but I am not able to find a way to do so. Is it possible without changing the group names in data?
Upvotes: 3
Views: 884
Reputation: 26630
You can change the labels via the scale, e.g.
library(tidyverse)
library(palmerpenguins)
penguins %>%
na.omit() %>%
mutate(species = factor(ifelse(species == "Adelie", 1, 2))) %>%
ggplot(aes(x = species, y = bill_length_mm)) +
geom_boxplot(aes(colour = species), notch = TRUE, varwidth = TRUE) +
geom_jitter(width = 0.2, aes(colour = species)) +
theme(legend.position = "none") +
labs(title="User Engagement Score", x="Condition", y="Score (max 140)") +
scale_x_discrete(label = c("Stealth", "Non-stealth"))
Upvotes: 2