I am trying to do a barplot using ggplot. The y axis labels are not coming properly but instead they are all cluttered at the bottom. Following is my code.. Can someone please help to fix this. Link of sample data (dput) given in google drive
t2 %>%
ggplot( aes(x=as.factor(Samples), y = variant, fill=SequenceOntology))
geom_bar(stat='identity')
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
https://drive.google.com/file/d/1OV36G08yd6RbFc3MlOFY12bDZDeeL_l4/view?usp=sharing
CodePudding user response:
You can achieve this by calling geom_tile()
instead of the geom_bar()
:
ggplot(t2, aes(x=as.factor(Samples), y=variant, fill=SequenceOntology))
geom_tile()
theme_classic()
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
Data:
t2 = structure(list(variant = c("1.25880583.SNV", "1.25880583.SNV",
"1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV",
"1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV",
"1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV",
"1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV",
"1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV",
"1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV",
"1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV",
"1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV",
"1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV",
"1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV",
"1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV",
"1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV",
"1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV",
"1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV",
"1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV",
"1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV",
"1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV",
"1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV",
"1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV",
"1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV",
"1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV",
"1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV",
"1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV", "1.25880583.SNV",
"1.25880583.SNV", "1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV",
"1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV",
"1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV",
"1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV",
"1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV",
"1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV",
"1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV",
"1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV",
"1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV",
"1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV",
"1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV",
"1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV",
"1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV",
"1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV",
"1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV",
"1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV",
"1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV",
"1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV",
"1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV",
"1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV",
"1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV",
"1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV",
"1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV",
"1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV", "1.25883780.SNV",
"1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV",
"1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV",
"1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV",
"1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV",
"1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV",
"1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV",
"1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV",
"1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV",
"1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV",
"1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV",
"1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV",
"1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV",
"1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV",
"1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV",
"1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV",
"1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV",
"1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV",
"1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV",
"1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV",
"1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV",
"1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV",
"1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV",
"1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV",
"1.25889632.SNV", "1.25889632.SNV", "1.25889632.SNV"), Samples = c(2137L,
1051L, 1059L, 1365L, 1374L, 1446L, 1452L, 1472L, 1473L, 1522L,
1537L, 1538L, 1553L, 1603L, 1637L, 1713L, 1722L, 1745L, 1770L,
180L, 1899L, 1903L, 1924L, 2135L, 2136L, 2237L, 2324L, 2327L,
2357L, 2364L, 2491L, 2607L, 2611L, 2614L, 2682L, 2723L, 2765L,
2787L, 2809L, 2820L, 2998L, 3009L, 3020L, 3033L, 3061L, 3152L,
3164L, 3165L, 3196L, 3198L, 3279L, 3304L, 3337L, 3361L, 3382L,
3407L, 3421L, 3423L, 3587L, 3797L, 3985L, 4070L, 4103L, 4118L,
4165L, 4177L, 4414L, 4476L, 470L, 4843L, 5515L, 5537L, 5715L,
5737L, 5845L, 5860L, 599L, 6062L, 6132L, 620L, 6443L, 6579L,
6824L, 7054L, 7143L, 715L, 751L, 753L, 7648L, 776L, 7860L, 806L,
899L, 949L, 987L, 1051L, 1059L, 1365L, 1374L, 1446L, 1452L, 1472L,
1473L, 1522L, 1537L, 1538L, 1553L, 1603L, 1637L, 1713L, 1722L,
1745L, 1770L, 1899L, 1903L, 1924L, 2135L, 2136L, 2137L, 2237L,
2324L, 2327L, 2357L, 2364L, 2491L, 2607L, 2611L, 2614L, 2682L,
2723L, 2765L, 2787L, 2809L, 2820L, 2998L, 3009L, 3020L, 3033L,
3061L, 3152L, 3164L, 3196L, 3198L, 3279L, 3304L, 3361L, 3382L,
3407L, 3421L, 3423L, 3587L, 3797L, 3985L, 4070L, 4103L, 4118L,
4177L, 4414L, 4476L, 470L, 4843L, 5515L, 5537L, 5715L, 5737L,
5845L, 5860L, 599L, 6062L, 6132L, 620L, 6443L, 6579L, 7143L,
715L, 751L, 7648L, 776L, 7860L, 806L, 899L, 949L, 987L, 180L,
3165L, 3337L, 4165L, 6824L, 7054L, 753L, 1452L, 1472L, 1553L,
1770L, 180L, 1903L, 2491L, 2607L, 2682L, 3009L, 3164L, 3382L,
3423L, 4476L, 5515L, 5537L, 5715L, 751L, 806L, 1051L, 1473L,
1522L, 1537L, 1538L, 1603L, 1637L, 1713L, 1722L, 1745L, 1899L,
1924L, 2135L, 2136L, 2137L, 2324L, 2327L, 2357L, 2611L, 2614L,
2723L, 2787L, 2809L, 2820L, 3033L, 3196L, 3198L, 3304L, 3337L,
3361L, 3407L, 3421L, 3587L, 3797L, 3985L, 4070L, 4103L, 4118L,
4165L, 4177L, 4414L, 4843L, 5737L, 5845L, 5860L, 599L, 6132L,
6443L, 6579L, 6824L, 7054L, 7143L, 753L, 7860L, 899L, 987L, 1059L,
1365L, 1374L, 1446L, 2237L, 2364L, 2765L, 2998L, 3020L, 3061L,
3152L, 3165L, 3279L, 470L, 6062L, 620L, 715L, 7648L, 776L, 949L
), SequenceOntology = c("intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "intron_variant",
"intron_variant", "intron_variant", "intron_variant", "missense_variant",
"missense_variant", "missense_variant", "missense_variant", "missense_variant",
"missense_variant", "missense_variant", "missense_variant", "missense_variant",
"missense_variant", "missense_variant", "missense_variant", "missense_variant",
"missense_variant", "missense_variant", "missense_variant", "missense_variant",
"missense_variant", "missense_variant", "missense_variant", "missense_variant",
"missense_variant", "missense_variant", "missense_variant", "missense_variant",
"missense_variant", "missense_variant", "missense_variant", "missense_variant",
"missense_variant", "missense_variant", "missense_variant", "missense_variant",
"missense_variant", "missense_variant", "missense_variant", "missense_variant",
"missense_variant", "missense_variant", "missense_variant", "missense_variant",
"missense_variant", "missense_variant", "missense_variant", "missense_variant",
"missense_variant", "missense_variant", "missense_variant", "missense_variant",
"missense_variant", "missense_variant", "missense_variant", "missense_variant",
"missense_variant", "missense_variant", "missense_variant", "missense_variant",
"missense_variant", "missense_variant", "missense_variant", "missense_variant",
"missense_variant", "missense_variant", "missense_variant", "missense_variant",
"missense_variant", "missense_variant", "missense_variant", "missense_variant",
"missense_variant", "missense_variant", "missense_variant", "missense_variant",
"missense_variant", "missense_variant", "missense_variant", "missense_variant",
"missense_variant", "missense_variant", "missense_variant", "missense_variant",
"missense_variant", "missense_variant", "missense_variant", "missense_variant",
"missense_variant", "missense_variant", "missense_variant", "missense_variant",
"missense_variant", "missense_variant", "missense_variant", "missense_variant",
"missense_variant", "missense_variant")), class = c("data.table",
"data.frame"), row.names = c(NA, -285L), sorted = "variant")