Home > OS >  R how to increase spacing between X and Y axis value labels
R how to increase spacing between X and Y axis value labels

Time:11-10

I'm currently doing performing an applied research about voting methodologies in the US presidential elections. I'm using R to visualize the data I've received from the government.

I'm currently trying to display the amount of voting machines used per state. It works but the labels are barely readable. This is the R-code I've used to create my plot:

    ggplot(data = e_2020_Voting_Machines_Per_State)  
  geom_point(mapping = aes(x = State_Abbr, y = totalMachines))   coord_flip()

With that code I get the following plot:

R studio plot

I'd like to increase the spacing between the State_Abbr names so that they're better readable.

I've searched for a solution for quite a bit now and I unfortunately haven't been able to find one yet.

Thank you very much for your help in advance!

CodePudding user response:

I've got to agree with user2974951. If you use the below code, you can adjust the width and height values to until there's enough spacing between the tick labels.

my_plot <- ggplot(data = e_2020_Voting_Machines_Per_State)  
  geom_point(mapping = aes(x = State_Abbr, y = totalMachines))   coord_flip()

tiff("my_plot.tiff", width = 8, height =6, units = "cm", res = 300)
print(my_plot)
dev.off()

Or, you can include element_text(size = 7) to your original ggplot() code to reduce the text size until they're all readable.

  • Related