0

I'm using ggplot2

rm(list=ls())
library(ggplot2)
library(scales)
library(grid)
library(gcookbook)
spi<-read.csv("netspill.csv",as.is=T)
attach(spi)
spi$date<-as.Date(spi$date)
str(spi)
datebreaks1<-seq(as.Date("2007-05-16"), as.Date("2013-05-31"), by="12 month")

'data.frame':   1848 obs. of  21 variables:
 $ obs          : int  257 258 259 260 261 262 263 264 265 266 ...
 $ date         : Date, format: "2007-05-16" "2007-05-17" "2007-05-18" ...
 $ spillvol     : num  19 18 18 17.4 17.5 ...
 $ CDStoasset   : chr  "16.22776618" "15.81730867" "15.36503932" "14.270632" ...
 $ assettocds   : chr  "19.62214133" "19.09211389" "18.49333545" "17.70890578" ...
 $ cdskopsi     : num  5.87 5.55 5.59 5.37 5.22 ...

and

   CDStoasset

then my data

"26.92311877" "26.48164709" "26.49961707" "26.59021979" "25.96024052" "25.94692576" "26.37937264" "27.11073195" "27.06050636" "26.91970508"
[1471] "29.00362056" "29.83671176" "29.55687587" "29.80806098" "29.42882282" "29.61759614" "29.57466413" "29.35304864" "29.36422448" "29.65128254"
[1481] "29.52697991" "29.85158673" "29.82680797" "30.22596306" "30.08997558" "29.76438051" "29.79329155" "29.89312089" "29.10694984" "28.75016179"
[1491] "26.95089819" "26.76647669" "26.73918817" "26.95267275" "27.58483418" "26.08107046" "26.19364923" "24.86188192" "25.75699619" "25.79200358"
[1501] "25.56374996" "25.70380996" "26.8145622"  "25.98075843" "24.39756886" "23.10004291" "22.66858838" "21.68670369" "22.79964894" "18.67955464"
[1511] "18.33640825" "16.86925316" "17.25132444" "19.63740405" "19.93870049" "22.89525288" "20.10651533" "30.43668745" "32.57389424" "#N/A"       
[1521] "#N/A"        "#N/A"        "37.81476543" "36.86642872" "37.66806016" "31.96648566" "31.26587858" "31.39916336" "31.86599313" "32.20460811"

contain N/A value.

cds<-ggplot(spi,aes(x=date,y=CDStoasset))+geom_line()  + labs(x = "", y = "")+ scale_y_continuous(breaks=seq(0,100,10))
cds

then error occur :Discrete value supplied to continuous scale:

and not showing graph.

How I can solve this problem?

please help me...

tonytonov
  • 25,060
  • 16
  • 82
  • 98
wawataiji
  • 19
  • 4
  • You could treat your `#N/A` values as `NA` by using `na.strings = "#N/A"` in `read.csv`. That way `CDStoasset` could be read as a continuous variable rather than a discrete variable like it is now. – aosmith Oct 31 '14 at 23:14
  • Thanks. I apply na.strings = "#N/A" in csv. and error is not occur. but this plot is very bed... in fact #N/A value is create line to 0. I want delete line graph.. how i can this? – wawataiji Nov 02 '14 at 17:40
  • It is difficult to troubleshoot without example data. Try including a [reproducible example](http://stackoverflow.com/a/5963610/2461552) and folks might be able to help more. – aosmith Nov 03 '14 at 16:02

2 Answers2

0

here is the answer from Eliminating NAs from a ggplot

you can set ggplot data like,

ggplot(data = subset([data_name], !is.na([data_name]), ..... )

to handle your N/A value.

so you can change your code like,

ggplot(data =(spi, !is.na(CDStoasset) ),aes(x=date,y=CDStoasset))+
  geom_line()  + 
  labs(x = "", y = "") + 
  scale_y_continuous(breaks=seq(0,100,10))

but i'm not sure it's the problem from N/A handling issue or not

0

Your y-values are characters, but you tell ggplot to use a continuous y-scale (this is also what the error message tries to tell you). If you run spi$CDStoasset <- as.numeric(spi$CDStoasset), that should fix the error.

Flo
  • 1,503
  • 1
  • 18
  • 35