How to delete a repetition on the x-axis on my facet grid of boxplots?


I am attempting to make a facet grid of boxplot split by the MS and HC condition in which participants 1-15 should be under MS and 16-20 should be under HC. I am unsure how the first facet containing the MS has an x point for 16 still. I'd like to get rid of this. Thank you!

Here is my script:
VAS_DATA$Condition <- factor(VAS_DATA$Condition, levels=c("MS","HC"))

##boxplot grouped by participant, separated by condition
Level_of_Change_Boxplot <- ggplot(data = VAS_DATA, mapping = aes(group =Participant.ID, x=Participant.ID, y = level_change, fill=Participant.ID)) +
geom_boxplot()+
scale_x_continuous("Participant ID", labels = as.character(VAS_DATA$Participant.ID), breaks = VAS_DATA$Participant.ID)+
labs(title='Level of Change Between VAS Responses of MS and HC',x='Participant ID',y='Degree of Change in Score Response')+
theme(plot.title = element_text(hjust = 0.5), legend.position="none")+
geom_jitter(position = position_jitter(height = 0, width = .3))+
facet_grid(~Condition, scales="free_x",space = "free_x")

You might want to treat ParticipantID as a factor rather than a continuous variable.

I can't test with your data but something like this:

VAS_DATA$Condition <- factor(VAS_DATA$Condition, levels=c("MS","HC"))
VAS_DATA$Participant.ID <- factor(VAS_DATA$Participant.ID)
##boxplot grouped by participant, separated by condition
Level_of_Change_Boxplot <- ggplot(data = VAS_DATA, mapping = aes(group =Participant.ID, x=Participant.ID, y = level_change, fill=Participant.ID)) +
  geom_boxplot()+
  labs(title='Level of Change Between VAS Responses of MS and HC',x='Participant ID',y='Degree of Change in Score Response')+
  theme(plot.title = element_text(hjust = 0.5), legend.position="none")+
  geom_jitter(position = position_jitter(height = 0, width = .3))+
  facet_grid(~Condition, scales="free_x",space = "free_x")

That worked perfectly, thank you! The colors are better too rather than hues of blue.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.