Axis text in ggplot

27 views
Skip to first unread message

Al Grasso

unread,
Mar 4, 2018, 10:33:24 AM3/4/18
to ggplot2
Hi all, I have a simple dataset made of 2 columns and 19 observations: FTD_DATE (19 dates between 2017 and 2018 formatted as dd/mm/yyyy) and FTD (integers between 11 and 199).
When I plot the data using:
 x <-ggplot(data=zed, aes(x=FTD_DATE,y=FTD)) +
  theme(axis.text.x = element_text
        (angle = 90, vjust = 0.5, hjust = 1.0)) +
  coord_cartesian(expand = TRUE) +
  #coord_cartesian(xlim=c(0,7)) +
  geom_point(aes(x=FTD_DATE,y=FTD))

The x axis contains all 19 observations. I am trying to retain all the observations in x but displaying only 6 or 7 of them in the axis text. If I add scale_x_discrete():

x <-ggplot(data=zed, aes(x=FTD_DATE,y=FTD)) +
  theme(axis.text.x = element_text
        (angle = 90, vjust = 0.5, hjust = 1.0)) +
  coord_cartesian(expand = TRUE) +
  #coord_cartesian(xlim=c(0,7)) +
  geom_point(aes(x=FTD_DATE,y=FTD))  +
scale_x_discrete(breaks=c("05/05/2017","03/06/2017","09/07/2017",
                          "11/10/2017","08/12/2017","08/01/2018",
                          "01/03/2018"))

I see only 7 data points in the x axis (as intended) but the text is grouped in the left part of the x axis followed by a large portion having no text..
I tried with scale_x_date to no avail.. Can someone propose a solution so as to display only 7 data points in the x axis, retaining all the 19 observations and making the x axis text well spread throughout the entire x axis? Possibly ordering the x text (FTD_DATE) in chronological? Thanks



Reply all
Reply to author
Forward
0 new messages