In ggplot geom_bar, the y axis labels are cluttered at the bottom of bar chart

arshad

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)) 

enter image description here

https://drive.google.com/file/d/1OV36G08yd6RbFc3MlOFY12bDZDeeL_l4/view?usp=sharing
Bushidov

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))

enter image description here

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")

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Adding a statistics table to the bottom of a ggplot, geom_bar chart in R

Breaking y-axis in ggplot2 with geom_bar

ggplot: geom_bar stacking order and labels

ggplot grouped geom_bar - adding labels of factor categories to the x-axis label

scaling x and y axis (geom_bar)

Remove some of the X axis labels in ggplot bar chart

How to add direct labels to a bar chart in ggplot for numeric x axis

bar chart R geom_bar changing legend and x axis

Is it possible to make a table with y axis labels of Highcharts bar chart?

Add y-axis value labels to gnuplot-bar chart

How can I put labels on geom_bar() in ggplot2 (without a manual y_position)

Show percent of total on top of geom_bar in ggplot2 while showing counts on y axis

Adjusting y axis origin for stacked geom_bar in ggplot2

Labelling geom_bar plot at a fixed distance from y-axis in ggplot

R ggplot2 geom_bar y-axis sequence similar to respective column values sequence

ggplot2. How to make geom_bar stacked chart y-range 0-100%?

Issues with labels in ggplot bar chart

R: ggplot stacked bar chart with counts on y axis but percentage as label

ggplot2 bar chart sign on y-axis

How to arrange y axis in bar chart using ggplot2

ggplot2 bar chart gives weird y axis

How to vertically center labels with geom_bar (ggplot2)

R ggplot2 geom_bar add labels with % sign

ggplot geom_bar with separate grouped variables on the x axis

Echarts Bar Chart Axis Label on Top and Bottom

Hide bottom x axis in horizontal bar chart?

How to color geom_bar by y-axis values?

Plot ratio of geom_bar on second y-axis

geom_bar tied exactly to x and y axis (without aggregating)

TOP Ranking

  1. 1

    How can I create a column whose entries depend on the contents of a column in another table?

  2. 2

    pump.io port in URL

  3. 3

    How to display items using sessions

  4. 4

    BigQuery - concatenate ignoring NULL

  5. 5

    no applicable method for 'mutate_' applied to an object of class "c('integer', 'numeric')"

  6. 6

    How i extract text from a model dialog in selenium?

  7. 7

    x no applicable method for 'tbl_vars' applied to an object of class "c('double', 'numeric')"

  8. 8

    AirflowException: Celery command failed - The recorded hostname does not match this instance's hostname

  9. 9

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  10. 10

    Most efficient regex for checking if a string contains at least 3 alphanumeric characters

  11. 11

    using excel range find return Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))

  12. 12

    redirect your computer port to url

  13. 13

    Can't create database with Symfony 4.1 : could not find driver

  14. 14

    How to fix "Exception evaluating SpringEL expression" error after submitting a variable Spring/Thymeleaf

  15. 15

    A python function to get the maximum value of a specific column, given a string that represents a table in CSV format

  16. 16

    Double spacing in rmarkdown pdf

  17. 17

    Uploading Files on production server returns either CORS error or POST 400 Bad Request using Apollo-Graphql

  18. 18

    Android Kotlin Unit test failing with io.mockk.MockKException: no answer found for

  19. 19

    Change Model input_shape but got an : ValueError: Input 0 of layer dense_44 is incompatible with the layer

  20. 20

    Formik, Yup - How to check is Decimal number

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive