I have a dataframe test
like below:
dput(test)
structure(list(Groups = c("Group1", "Group2", "Group3", "Group4",
"Group5", "Group6", "Group7", "Group8", "Group9", "Group10",
"Group11", "Group12", "Group13", "Group14", "Group15", "Group16",
"Group17", "Group18", "Group19", "Group20", "Group21", "Group22"
), Disease = c("Brain", "Brain", "Brain", "Blood", "Blood", "Esophagus",
"Esophagus", "Esophagus", "Brain", "Brain", "OE", "control",
"OE", "control", "OE", "control", "PE", "PE_X", "PE_X", "PE",
"PE_X", "PE"), variable = c("Name", "Name", "Name", "Name", "Name",
"Name", "Name", "Name", "Name", "Name", "Name", "Name", "Name",
"Name", "Name", "Name", "Name", "Name", "Name", "Name", "Name",
"Name"), value = c(1.079825876, 0.236961206, 0.286498286, 0.374978442,
3.620160544, 1.876875376, 0.293402656, 0.176208121, 0.622282653,
1.373705338, 9.235592994, 1.437889832, 8.70900915, 1.772903362,
9.070885831, 1.792899823, 10.29580836, 1.373281466, 4.210242765,
0, 7.331498976, 14.11415563)), class = "data.frame", row.names = c(NA,
-22L))
Using below code I made a boxplot:
ggplot(data= subset(test, variable == "Name")) +
geom_boxplot(aes(x=Disease, y=value, fill=Disease), outlier.shape=NA) +
geom_jitter(aes(x=Disease, y=value, fill=Disease), position=position_dodge(0.2)) +
theme_classic(base_size = 12) + xlab("") + ylab("value")
Using the below code I reordered the x-axis names (Disease)
based on the column value
.
ggplot(data= test) +
geom_boxplot(aes(x=reorder(Disease,value, na.rm=TRUE), y=value, fill=Disease), outlier.shape=NA) +
geom_jitter(aes(x=Disease, y=value, fill=Disease), position=position_dodge(0.2)) +
theme_classic(base_size = 12) + xlab("") + ylab("value")
Question: I would like to reorder only Blood, Brain, Eophagus Diseases on x-axis
and keep the rest of the Diseases on the right side of the plot. How to do this?