rggplot2geomscatterpie

Why are dates showing as numbers instead of as months in ggplot in R?


My x axis is showing number instead of months, how can I modify so it shows January, February and March?

data<- data.frame(Dates= rep(
  seq(as.Date('2017-01-01'), as.Date('2017-03-03'), by = 'months')),
          A=c(28.0,20.6,15.8),
          B= c(0,12.7,6.5),
          C= c(0,1.49,6.96),
  Variable1= c(1,1,1))

trans_x <- function(x)round(coef(m1)[1] + coef(m1)[2]*x)

ggplot() + 
  geom_scatterpie(data = data, aes(x = Dates , y = Variable1, group = Dates, r=4), cols = c("A","B","C")) +
  scale_y_log10() +
  coord_fixed()+
  theme_classic()+
  theme(axis.text.y = element_blank())+
   scale_fill_grey()

enter image description here


Solution

  • As @Mohanasundaram said right in the comments, you can use the scales package to format your date using date_format in the scale_x_date function like this:

    library(tidyverse)
    library(scatterpie)
    library(scales)
    ggplot() + 
      geom_scatterpie(data = data, aes(x = Dates , y = Variable1, group = Dates, r=4), cols = c("A","B","C")) +
      scale_y_log10() +
      coord_fixed()+
      theme_classic()+
      theme(axis.text.y = element_blank())+
      scale_fill_grey() +
      scale_x_date(labels = date_format("%Y-%B-%d"))
    

    Output:

    enter image description here