Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
319 views
in Technique[技术] by (71.8m points)

How do I stop ggplot2 overlapping all my x axis scale labels?

I wrote a code to produce 96 line graphs in ggplot2. It used to work fine, but today the plot has all the x axis scale labels in one place, overlapping. How do I stop this?

My data frame (df2) looks like this:

# A tibble: 9,312 x 5
   Sample Column Row    time    OD
    <int>  <int> <chr> <dbl> <dbl>
 1      1      1 a         0 0.110
 2      1      1 a      1800 0.112
 3      1      1 a      3600 0.113
 4      1      1 a      5400 0.115
 5      1      1 a      7200 0.118
 6      1      1 a      9000 0.124
 7      1      1 a     10800 0.132
 8      1      1 a     12600 0.142
 9      1      1 a     14400 0.155
10      1      1 a     16200 0.171
# ... with 9,302 more rows

and my code is:

#This prints a line plot of df2 with OD against time
#facet_grid allows 96 small line plots
ggplot(df2, aes(x= time, y= OD)) +
  #Sets colour of line to red
  geom_line(aes(colour="red")) +
  #removes legend
  guides(colour = "none") +
  facet_grid(Row ~ Column) +
  theme_light() +
  #turns the x acis labels 90 degrees so they aren't overlapping
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5)) +
  # changes the X axis scale. From 0 to 48 in increments of 12
  scale_x_continuous(breaks = seq(0, 48, by = 12)) +
  #labels the x axis 
  labs(x = "Time (hours)")

and here's the plot that it produces with the weird X scale plot

Each of the line graphs is correct, so the axis is working, but the labels are weird.

question from:https://stackoverflow.com/questions/65886990/how-do-i-stop-ggplot2-overlapping-all-my-x-axis-scale-labels

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...