[R] ggplot y-axis labels are not continuous

Mohan Radhakrishnan radhakrishnan.mohan at gmail.com
Sun Sep 14 10:15:30 CEST 2014


Thanks Dennis.

df.melted$value<-as.numeric(df.melted$value)
df.melted$value <- format(df.melted$value, scientific = FALSE)


Mohan

On Sun, Sep 14, 2014 at 9:22 AM, Dennis Murphy <djmuser at gmail.com> wrote:

> Hi:
>
> Try
>
> str(df.melted)
>
> I'm guessing value is a factor. It needs to be numeric or integer.
>
> Dennis
>
>
> On Sat, Sep 13, 2014 at 12:53 PM, Mohan Radhakrishnan
> <radhakrishnan.mohan at gmail.com> wrote:
> > Hi,
> >
> > This is the code to create a ggplot. The plot is rendered but the y-axis
> > labels are not continuous. So the lines are split.
> >
> > Moreover multiple y-axis labels overwrite each other due to this. How
> can I
> > fix this?
> >
> > If I try to set ylim I get "
> >
> > *Discrete value supplied to continuous scale"*
> >
> > library(RJSONIO)
> > library(ggplot2)
> > this.dir <- dirname(parent.frame(2)$ofile)
> > setwd(this.dir)
> >
> > airlines   = fromJSON("json")
> > df <- sapply(airlines$data,unlist)
> > df <- data.frame(t(df))
> > colnames(df) <- c( (airlines[[1]][[1]])[[2]],
> > gsub("[^A-Z]","",(airlines[[1]][[2]])[[2]]),
> > gsub("[^A-Z]","",(airlines[[1]][[3]])[[2]] ),
> > gsub("[^A-Z]","",(airlines[[1]][[4]])[[2]]), (airlines[[1]][[5]])[[2]],
> > (airlines[[1]][[6]])[[2]], (airlines[[1]][[7]])[[2]],
> > (airlines[[1]][[8]])[[2]],
> > (airlines[[1]][[9]])[[2]],(airlines[[1]][[10]])[[2]] )
> >
> > df.melted <- melt(df, id = "YEAR")
> > print(ggplot(data = df.melted, aes(x = YEAR, y = value, color =
> variable))
> > +geom_point() + theme(axis.text.x = element_text(angle = 90, hjust = 1))
> +
> > ylab(""))
> > dev.off()
> >
> >
> >> head(df)
> >
> >      YEAR INTERNATIONALACMINNOS DOMESTICACMINNOS TOTALACMINNOS
> >
> > 1 1995-96                 92515           314727        407242
> >
> > 2 1996-97                 94884           324462        419346
> >
> > 3 1997-98                 98226           317531        415757
> >
> > 4 1998-99                 99563           325392        424955
> >
> > 5 1999-00                 99701           368015        467716
> >
> > 6 2000-01                103211           386575        489786
> >
> >   INTERNATIONAL PAX (IN NOS) DOMESTIC PAX (IN NOS) TOTAL PAX (IN NOS)
> >
> > 1                   11449756              25563998           37013754
> >
> > 2                   12223660              24276108           36499768
> >
> > 3                   12782769              23848833           36631602
> >
> > 4                   12916788              24072631           36989419
> >
> > 5                   13293027              25741521           39034548
> >
> > 6                   14009052              28017568           42026620
> >
> >   INTERNATIONAL FREIGHT (IN MT) DOMESTIC FREIGHT (IN MT) TOTAL FREIGHT
> (IN
> > MT)
> >
> > 1                        452853                   196516
> > 649369
> >
> > 2                        479088                   202122
> > 681210
> >
> > 3                        488175                   217405
> > 705580
> >
> > 4                        474660                   224490
> > 699150
> >
> > 5                        531844                   265570
> > 797414
> >
> > 6                        557772                   288373
> > 846145
> >
> >
> > Thanks,
> >
> > Mohan
> >
> >         [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list