Entering edit mode
2.0 years ago
prithvi.mastermind
▴
50
I wish to control the width of my boxes in box-and-whisker plots. Pleas help me to do
My Code:
library(tidyverse)
library(palmerpenguins)
library(ggplot2)
library(datasets)
library(RColorBrewer)
library(ggpubr)
library(DAAG)
library(nlme)
library(viridisLite)
library(ggbeeswarm)
expr <- read.delim("LUAD_BOX1.txt", stringsAsFactors = FALSE, header = TRUE)
ggplot(data = expr,aes(x = Type, y = TDRKH, fill = Type)) + stat_boxplot(geom = "errorbar", width=0.2) + geom_boxplot(width=0.5,outlier.shape=NA) + scale_fill_viridis_d(option = "D") + theme_pubr() + scale_fill_manual(values=c("green", "red")) + theme(text = element_text(size=16),plot.title = element_text(hjust = 0.5, face="bold", size=16), axis.title.y = element_text(size=16, face="bold", margin=margin(r=16)), axis.title.x = element_text(size=16, face="bold", margin=margin(t=16)), axis.text = element_text(size=16, face="bold", color="black"), legend.key.size = unit(2,"line"))+ theme(legend.text = element_text(size = 16)) + theme(legend.title = element_text(size = 16))
My Data:
Sample Type TDRKH Sex Smoking Status
TCGA.38.4625.01A Tumor 0.6500694 female Reformed Smoker1
TCGA.38.4625.11A Normal -0.5658817 female Normal
TCGA.38.4627.01A Tumor -0.5830916 female Non-smoker
TCGA.38.4627.11A Normal -1.209234 female Normal
TCGA.38.4632.01A Tumor 1.146363 male Reformed Smoker2
TCGA.38.4632.11A Normal -0.3336032 male Normal
TCGA.44.2655.01A Tumor 2.024474 female Smoker
TCGA.44.2655.11A Normal -0.6665133 female Normal
TCGA.44.2657.01A Tumor 0.171917 female Smoker
TCGA.44.2657.11A Normal -0.4269736 female Normal
TCGA.44.2661.01A Tumor 0.1126025 female Non-smoker
TCGA.44.2661.11A Normal -0.7238899 female Normal
TCGA.44.2662.01A Tumor 1.273534 male Smoker
TCGA.44.2662.11A Normal -0.6356711 male Normal
TCGA.44.2665.01A Tumor 0.009561531 female Non-smoker
TCGA.44.2665.11A Normal -1.191961 female Normal
TCGA.44.2668.01A Tumor 0.9272611 male Smoker
TCGA.44.2668.11A Normal -0.6641366 male Normal
TCGA.44.3396.01A Tumor -0.1383681 female Reformed Smoker1
TCGA.44.3396.11A Normal -0.8337708 female Normal
TCGA.44.6145.01A Tumor 1.290406 female Smoker
TCGA.44.6145.11A Normal -0.7956443 female Normal
TCGA.44.6147.01A Tumor 0.6861114 female Smoker
TCGA.44.6147.11A Normal -1.364572 female Normal
TCGA.44.6776.01A Tumor 0.3604824 female Smoker
TCGA.44.6776.11A Normal -0.5145122 female Normal
TCGA.44.6777.01A Tumor 1.095746 female Smoker
TCGA.44.6777.11A Normal -0.4956391 female Normal
TCGA.44.6778.01A Tumor 0.2749578 male Smoker
TCGA.44.6778.11A Normal -0.9877578 male Normal
TCGA.49.4490.01A Tumor 0.03521947 female Non-smoker
TCGA.49.4490.11A Normal -0.715968 female Normal
TCGA.49.4512.01A Tumor 1.154696 female Non-smoker
TCGA.49.4512.11A Normal -0.4981203 female Normal
TCGA.49.6743.01A Tumor 1.403125 female Non-smoker
TCGA.49.6743.11A Normal -0.9275845 female Normal
TCGA.49.6744.01A Tumor 0.300926 female Non-smoker
TCGA.49.6744.11A Normal -0.9610111 female Normal
TCGA.49.6745.01A Tumor 0.228453 male Non-smoker
TCGA.49.6745.11A Normal -0.801721 male Normal
TCGA.49.6761.01A Tumor 1.437622 female Non-smoker
TCGA.49.6761.11A Normal -0.2979129 female Normal
TCGA.50.5930.01A Tumor 1.570507 male Non-smoker
TCGA.50.5930.11A Normal -0.4416968 male Normal
TCGA.50.5931.01A Tumor 0.3775715 female Non-smoker
TCGA.50.5931.11A Normal -0.6317542 female Normal
TCGA.50.5932.01A Tumor 1.211618 male Non-smoker
TCGA.50.5932.11A Normal -0.7908115 male Normal
TCGA.50.5933.01A Tumor 1.576859 male Non-smoker
TCGA.50.5933.11A Normal -1.06927 male Normal
TCGA.50.5935.01A Tumor 2.029953 female Non-smoker
TCGA.50.5935.11A Normal -0.8517754 female Normal
TCGA.50.5939.01A Tumor -0.1612658 male Reformed Smoker2
TCGA.50.5939.11A Normal -0.7112667 male Normal
TCGA.50.6595.01A Tumor -1.05404 female Reformed Smoker2
TCGA.50.6595.11A Normal -0.5675514 female Normal
TCGA.55.6968.01A Tumor 1.025638 male Non-smoker
TCGA.55.6968.11A Normal -0.2956288 male Normal
TCGA.55.6970.01A Tumor 0.8346801 female Non-smoker
TCGA.55.6970.11A Normal -0.5011233 female Normal
TCGA.55.6971.01A Tumor 0.9952134 female Smoker
TCGA.55.6971.11A Normal -0.4348784 female Normal
TCGA.55.6972.01A Tumor 1.663106 male Non-smoker
TCGA.55.6972.11A Normal -1.005711 male Normal
TCGA.55.6975.01A Tumor -0.08286432 male Reformed Smoker2
TCGA.55.6975.11A Normal -0.3230795 male Normal
TCGA.55.6978.01A Tumor -0.248721 male Non-smoker
TCGA.55.6978.11A Normal -0.7937661 male Normal
TCGA.55.6979.01A Tumor 0.4372139 female Non-smoker
TCGA.55.6979.11A Normal -0.737069 female Normal
TCGA.55.6980.01A Tumor 0.7107928 male Non-smoker
TCGA.55.6980.11A Normal -0.6998034 male Normal
TCGA.55.6981.01A Tumor 0.7467579 female Non-smoker
TCGA.55.6981.11A Normal -1.270066 female Normal
TCGA.55.6982.01A Tumor 0.2045792 female Non-smoker
TCGA.55.6982.11A Normal -0.864682 female Normal
TCGA.55.6984.01A Tumor -0.6147963 female Non-smoker
TCGA.55.6984.11A Normal -0.9993112 female Normal
TCGA.55.6985.01A Tumor 0.2640623 female Non-smoker
TCGA.55.6985.11A Normal -0.825988 female Normal
TCGA.55.6986.01A Tumor 0.161682 female Non-smoker
TCGA.55.6986.11A Normal -1.345103 female Normal
TCGA.73.4676.01A Tumor 1.945119 male Smoker
TCGA.73.4676.11A Normal -1.073368 male Normal
TCGA.91.6828.01A Tumor 1.327468 male Reformed Smoker2
TCGA.91.6828.11A Normal -0.8411406 male Normal
TCGA.91.6829.01A Tumor 1.390523 male Smoker
TCGA.91.6829.11A Normal -0.6558897 male Normal
TCGA.91.6831.01A Tumor 0.8284916 male Non-smoker
TCGA.91.6831.11A Normal -1.071139 male Normal
TCGA.91.6835.01A Tumor 1.839444 female Non-smoker
TCGA.91.6835.11A Normal -0.9248294 female Normal
TCGA.91.6836.01A Tumor 3.60664 female Reformed Smoker1
TCGA.91.6836.11A Normal -0.05054061 female Normal
TCGA.91.6847.01A Tumor 0.9409349 female Reformed Smoker2
TCGA.91.6847.11A Normal -0.8595158 female Normal
TCGA.91.6849.01A Tumor 1.131687 female Smoker
TCGA.91.6849.11A Normal -1.165171 female Normal
Thank you so much for your help.
A small educational note: if an answer was helpful, you should upvote it; if the answer resolved your question, you should mark it as accepted. You can accept more than one answer if they work. This will help future users that might find this post find the right answer.