lhc0003
lhc0003

Reputation: 49

Change font size of each column in simple bar plot so that all labels are visible?

Here is the code that I used to create the table

barplot(sort(table(df$Department_lower), decreasing=TRUE))

Here is a sample of the table data

sample data picture

Here is the result. We need labels for all columns to be visible

The bar chart looks good but you cannot see the column name for all 9 levels

Upvotes: 1

Views: 510

Answers (1)

Quinten
Quinten

Reputation: 41603

An option would be rotation the labels of your x-axis using las = 2. I created some extra random labels to give you a reproducible example. First a before plot:

df <- data.frame(Department_lower=sample(c('labelA', 'entrees', 'salad', 'labelB', 'general', 'catering', 'swag', 'labelC', 'labelD'),
                                   50, replace=TRUE))

plot <- barplot(sort(table(df$Department_lower), decreasing=TRUE)) 

Before:

enter image description here

Rotating x-axis labels:

plot <- barplot(sort(table(df$Department_lower), decreasing=TRUE), las = 2)

Output:

enter image description here

Upvotes: 1

Related Questions