Y-axis tick labels appearing out of place on top of each other

Hey all,

I have the following code to plot a graph:

ggplot(merged,aes(x = as.factor(`Branch Code`),y = as.factor(`Case Type`))) + geom_bar(stat = "identity") + theme_classic() + theme(axis.text.x=element_text(angle=45,vjust=0.5),axis.title.x=element_text(vjust=-1),plot.title = element_text(hjust=0.5)) + ggtitle("Distribution of case types") + xlab("Branch Code") + ylab("Case Type")

This gives me the following graph:

However, the y-axis labels are not equally/regularly spaced as they should be...

I have a minimal reproducible example below.

Would anybody be able to give me a helping hand?

structure(list(`Branch Code` = c(80012, 80012, 80012, 80012, 
80012, 80012), `Location Type` = c("Rural", "Rural", "Rural", 
"Rural", "Rural", "Rural"), Type = c("LM", "LM", "LM", "LM", 
"LM", "LM"), Status = c("Open", "Open", "Open", "Open", "Open", 
"Open"), Segment = c("Agency", "Agency", "Agency", "Agency", 
"Agency", "Agency"), `Multiple (partner that owns multiple branches)` = c("Multiple 13", 
"Multiple 13", "Multiple 13", "Multiple 13", "Multiple 13", "Multiple 13"
), RetailType = c("Convenience", "Convenience", "Convenience", 
"Convenience", "Convenience", "Convenience"), `Volume of transactions` = c(1130, 
1130, 1130, 1130, 1130, 1130), `Open hours` = c(108.25, 108.25, 
108.25, 108.25, 108.25, 108.25), `X Pos` = c(551872, 551872, 
551872, 551872, 551872, 551872), `Y Pos` = c(170269, 170269, 
170269, 170269, 170269, 170269), Urbanity = c("Medium Density", 
"Medium Density", "Medium Density", "Medium Density", "Medium Density", 
"Medium Density"), `Case Reference Number` = c("1967808-C5F1P3", 
"1962373-N7X5C2", "2052107-N2R3C8", "2122905-K9T0M7", "2149177-H3W7C9", 
"2143459-L4X2D8"), `Created On` = structure(c(1625672980, 1625233808, 
1632225098, 1637064726, 1638808983, 1638376615), tzone = "UTC", class = c("POSIXct", 
"POSIXt")), `Branch Type` = c("Main", "Main", "Main", "Main", 
"Main", "Main"), L1 = c("Back Office", "Mails", "Mails", "DVLA", 
"DVLA", "Post Office - ATM"), L2 = c("Cash Handling and Distribution", 
"Accounting and Despatch", "Redirection", "Counter Procedure", 
"Methods of payment", "Post Office - ATM"), L3 = c("Bank Holiday Arrangements", 
"Despatch Report", "Counter Procedure", "Reversal", "Methods of Payment", 
"Post Office - ATM"), L4 = c("Bank Holiday Arrangements", "Correcting/Resolving", 
"Business", "After Cut Off", "Methods of Payment", "QR Code is not scanning Error Handling"
), `Case Type` = c("Question", "Question", "Question", "Question", 
"Question", "Question")), row.names = c(NA, -6L), class = c("tbl_df", 
"tbl", "data.frame"))

Setting y to Case Type doesn't make sense for a column chart. The y value should be numeric. What is your goal?

1 Like

Yes I have plotted a scatter plot instead and it now works great!

This topic was automatically closed 7 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.