Error In Xy.coords R
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn error in stripchart.default(x1, ...) : invalid plotting method more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags plot list in r Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like
Error In Plot.window(...) : Need Finite 'xlim' Values
you, helping each other. Join them; it only takes a minute: Sign up 'x' and 'y' lengths differ ERROR up vote 0 down vote favorite I just started using R. I am supposed to Calculate a new variable
Plot Type In R
“Vehic_vol” from the sum of “Psgr_Vol” and “Lugg_Vol” and Plot this new variable against “CITY_MPG” for the whole data set but I end up with 'x' and 'y' lengths differ ERROR! Any thoughts? Here is what I did: Vehic_vol<-(VehicleData$Psgr_Vol + VehicleData$Lugg_Vol) plot (VehicleData$Vehic_vol, VehicleData$CITY_MPG) Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ r share|improve this question edited May 16 '15 at 23:45 Maven 324513 asked Jan 15 '15 at 17:30 Farshad plotting in r 514 add a comment| 1 Answer 1 active oldest votes up vote 1 down vote accepted From the code you provided, Vehic_vol is not a column of VehicleData. If you enter in VehicleData$Vehic_vol it returns NULL Note that NULL and VehicleData$CITY_MPG have different lengths (use length() to verify that). Try this instead plot (Vehic_vol, VehicleData$CITY_MPG) or VehicleData$Vehic_vol <- (VehicleData$Psgr_Vol + VehicleData$Lugg_Vol) plot (VehicleData$Vehic_vol, VehicleData$CITY_MPG) share|improve this answer answered Jan 15 '15 at 17:38 blakeoft 1,205413 General rule suggestion: In my R code I tend to separate a "add derived values to my dataframe" phase from a "now use the extended stuff for plotting" phase. In this manner of working you would have written VehicleData$Vehic_vol <- (VehicleData$Psgr_Vol + VehicleData$Lugg_Vol) (variant 2 of above) and the subsequent plot command would have worked as you wanted it to as a matter of course (without straining your short term memory much). –Lutz Prechelt Jan 16 '15 at 18:54 Thanks for help –Farshad Jan 18 '15 at 1:42 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not t
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about
Lines R
Stack Overflow the company Business Learn more about hiring developers or posting ads scatterplot in r with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow error in plot.new() : figure margins too large is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up R error in xy.coords up vote 0 down vote favorite I am using http://stackoverflow.com/questions/27969434/x-and-y-lengths-differ-error the R package "sdcMicro" and I have tried a working example at ?sdcMicro, but cannot use the plot method. Working example: install.packages("sdcMicro", depend = TRUE) library(sdcMicro) data(free1) f <- freqCalc(free1, keyVars = 1:3, w = 30) ind <- indivRisk(f) class(ind) [1] "indivRisk" plot(ind) I get the message: Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' is a list, but does not have components 'x' and 'y' If I try http://stackoverflow.com/questions/21850342/r-error-in-xy-coords methods(class = indivRisk) I get: [1] print.indivRisk According to (http://www.tdp.cat/issues/tdp.a004a08.pdf), the methods of class "indivRisk" should be plot.indivRisk print.indivRisk The plot method helps analysis of data. I don't understand why I don't have this method. Can anyone help me or guide me to an explaination? I am using RGui (64-bit) on Windows 7. r plot share|improve this question edited Feb 18 '14 at 12:01 Richie Cotton 57.3k16126231 asked Feb 18 '14 at 10:07 Sisse 126313 add a comment| 1 Answer 1 active oldest votes up vote 0 down vote You are correct; there is no print.indivRisk method. Looking at the structure of ind: str(ind) ## List of 5 ## $ rk : num [1:4000] 0.00121 0.00421 0.00421 0.00421 0.00169 ... ## $ method: chr "approx" ## $ qual : num 1 ## $ fk : int [1:4000] 8 3 3 3 6 6 4 7 5 3 ... ## $ knames: chr [1:3] NA NA NA ## - attr(*, "class")= chr "indivRisk" maybe you just want a histogram of the rk element. hist(ind$rk) or library(ggplot2) ggplot(data.frame(rk = ind$rk), aes(rk)) + geom_histogram() share|improve this answer answered Feb 18 '14 at 12:04 Richie Cotton 57.3k16126231 Thanks a lot for suggestions. Unfortunately the plot(s) should be the b
E. Threaded Open this post in threaded view ♦ ♦ | Report Content as Inappropriate ♦ ♦ Scatter plot produces "'x' and 'y' lengths differ" Hello, I am working on a project to http://r.789695.n4.nabble.com/Scatter-plot-produces-quot-x-and-y-lengths-differ-quot-td3604367.html create some scatter plots. I have syntax for 26 plots, and 22 of them http://rstudio-pubs-static.s3.amazonaws.com/15186_d0866b09fe3d415bb202099b25a855fd.html display as they should. But here, for example, is a sample of the command syntax I am using: good <- complete.cases(affect1,adh1scr) plot (jitter(affect1,2.0),jitter(adh1scr,1.0),xlim=c(1,35),ylim=c(1,35),pch=1 6, main='Adherence Score by Affectiveness Level - Visit 1', ylab='Adherence score',xlab='Affect Scale - Patient Survey',abline(lsfit(affect1,adh1scr)),col="red") lines(lowess(affect1[good], adh1scr[good]), col="blue") I run this and get: > good <- complete.cases(affect1,adh1scr) > plot (jitter(affect1,2.0),jitter(adh1scr,1.0),xlim=c(1,35),ylim=c(1,35),pch=1 6, error in + main='Adherence Score by Affectiveness Level - Visit 1', + ylab='Adherence score',xlab='Affect Scale - Patient Survey',abline(lsfit(affect1,adh1scr)),col="red") Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ > lines(lowess(affect1[good], adh1scr[good]), col="blue") Error in xy.coords(x, y) : 'x' and 'y' lengths differ The data is a bit skewed towards the high end, but I found other variables that skew even more and they produce graphs. I've taken out error in xy.coords the ABLINE and LINES options and the problem persists. I tried changing the name of the AFFECT1 variable, the problem exists. I tried changing the values of XLIM and YLIM (the range for the X and Y variables are both 1 and 35); I still get the same error. There are enough valid cases to create a scatter plot (two of the plots will have 211 valid cases, the other two will have 163 valid cases). This occurs in the middle of my command file. So - I know that the variables are being read into R correctly (no error messages from R when I define the variables), and similar syntax for other variables works - it's just these 4 variables (AFFECT1, AFFECT2, INFOSC1, INFOSC2) that produce the "Error in xy.coords" message. Any help that anyone can give regarding this would be helpful. Sincerely, Steve Alspach Jesse Brown Veterans' Administration Hospital [hidden email] [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code. Daniel Malter Threaded Open this post in threaded view ♦ ♦ | Report Content as Inappropriate ♦ ♦ Re: Scatter plot produces "'x' and 'y' lengths
'data.frame': 150 obs. of 5 variables: ## $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ... ## $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ... ## $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ... ## $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ... ## $ Species : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ... summary(iris) ## Sepal.Length Sepal.Width Petal.Length Petal.Width ## Min. :4.30 Min. :2.00 Min. :1.00 Min. :0.1 ## 1st Qu.:5.10 1st Qu.:2.80 1st Qu.:1.60 1st Qu.:0.3 ## Median :5.80 Median :3.00 Median :4.35 Median :1.3 ## Mean :5.84 Mean :3.06 Mean :3.76 Mean :1.2 ## 3rd Qu.:6.40 3rd Qu.:3.30 3rd Qu.:5.10 3rd Qu.:1.8 ## Max. :7.90 Max. :4.40 Max. :6.90 Max. :2.5 ## Species ## setosa :50 ## versicolor:50 ## virginica :50 ## ## ## Now lets make a graph of the whole data (by a slightly roundabout way that will be better suited to demonstrate subsetting) plot(iris$Petal.Length, iris$Petal.Width, type="n") points(iris$Petal.Length, iris$Petal.Width, pch=19, col=iris$Species) Now we can make a subset using the common [] operator plot(iris$Petal.Length, iris$Petal.Width, type="n") points(iris$Petal.Length[iris$Species=="setosa"], iris$Petal.Width[iris$Species=="setosa"], pch=19, col=iris$Species[iris$Species=="setosa"]) Which is basically saying graph the Petal Length (of those cases where the Species is setosa) against the Petal Width (of those cases where the Species is setosa). There is actually a really common error people make at this point. If you put in the code plot(iris$Petal.Length, iris$Petal.Width, type="n") points(iris$Petal.Length[iris$Species=="setosa"], iris$Petal.Width, pch=19, col=iris$Species[iris$Species=="setosa"]) you will get the error message Error in xy.coords(x, y, xlabel, ylabel, log) : ‘x’ and ‘y’ lengths differ Which is caused because you are trying to compare something which has a subset on it (Petal