Why do I get an error when I run some examples from the online ggplot2 reference manual? - r

Trying the ggplot2 examples in the online reference manual, and particularly in this page, I fail to produce all but the first of the second example's plots.
> d + stat_density2d(geom="tile", aes(fill = ..density..), contour = FALSE)
Error in `[<-.data.frame`(`*tmp*`, var, value = list(`NA` = NULL)) :
missing values are not allowed in subscripted assignments of data frames
In addition: Warning message:
Removed 34912 rows containing missing values (stat_density2d).
I have R ver. 2.10.1 and ggplot2 ver. 0.8.6
What is wrong?

It seems to be the bug reported here:
http://groups.google.com/group/ggplot2/browse_thread/thread/6a7929d2b122efb2

Related

ggplot2 in R -- error message and then also no points being plotted

I am working on my data analytics cert (google) on Coursera and there is a hands on activity with ggplot.
It tells me to type this:
ggplot(data = penguins) + geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g))
into the console, so I did and got this error message:
Error in draw_axis(break_positions = guide$key[[aesthetic]], break_labels = guide$key$.label, :
lazy-load database '/home/rstudio-user/R/x86_64-pc-linux-gnu-library/4.0/gtable/R/gtable.rdb' is corrupt
In addition: Warning messages:
1: Removed 2 rows containing missing values (geom_point).
2: In draw_axis(break_positions = guide$key[[aesthetic]], break_labels = guide$key$.label, :
restarting interrupted promise evaluation
3: In draw_axis(break_positions = guide$key[[aesthetic]], break_labels = guide$key$.label, :
internal error -3 in R_decompress1
When I then put quote marks around the column names, I at least got what looks like a plot, but absolutely no points on the graph. I tried with different col names, because maybe something isn't a number? but that didn't matter, nothing happens with the plot.
Coursera is not really a whole lot of help, and I've been trying to get help from others in the course (since I'm taking it thru an organization) but haven't been able to get any help. Is there someone out there who sees what I'm doing wrong?

Problem with R code: Computation failed in `stat_signif()`: not enough 'y' observations

I am trying to compare two groups with 47 observations in each and tried to include the significance level using ggsignif but it gives me this error message :
Computation failed in stat_signif():
not enough 'y' observations
This is the data :enter image description here
The first group being "Un-C_SL" / "Un-C_RL" / "Un-C" and the second one that doesn't appear in the image is "Vp_SL" / "Vp_RL" / "Vp"
This is the code I used:
ggplot(UnC_Vp_2, aes(x = Condition, y = Biomass)) + geom_boxplot() + geom_signif(comparisons = list("Un-C", "Vp"), map_signif_level = TRUE)
I was able to get the box plot but not the significance level. What should I do?
The comparisons = argument needs a list() of pairwise comparisons that are each contained in a c(), so it should work if you change it to comparisons = list(c("Un-C", "Vp")).
See this github issue also. I found this question when I had the same problem; I had forgotten it needed to be a list and not just c() and I agree that a more informative error message would help.

ggsurvplot warning"Warning messages: 1: Removed 1 rows containing missing values (geom_text) "

I am using ggsurvplot to create a kaplan-meier curve. I get the following warning message "Warning messages: 1: Removed 1 rows containing missing values (geom_text)." I have seen other posts that are similar and have solved the problem when the image is geom_point.
But the proposed solution [Explain ggplot2 warning: "Removed k rows containing missing values" of adding coord_cartesian does not work with ggsurvplot. I know that I can simply expand my y-axis to remove this warning message but i dont want to do that because then you are unable to differentiate when the curves separate.
My code:
ggsurvplot(survival.primary, ylim=c(0.0,0.20), xlim=c(0,1500), break.x.by=180, censor = F, risk.table = T, fun = "event")
Thank you very much!

Using the QQ Plot functionality in ggplot

I'm brand new to R, and have a data frame with 8 columns that has daily changes in interest rates. I can plot QQ plots for data each of the 8 columns using the following code:
par(mfrow = c(2,4))
for(i in 1:length(column_names)){
qqnorm(deltaIR.df[,i],main = column_names[i], pch = 16, cex = .5)
qqline(deltaIR.df[,i],cex = .5)
}
I'd like now to use the stat_qq function in the ggplot2 package to do this more elegantly, but just can't get my arms around the syntax - I keep getting it wrong. Would someone kindly help me translate the above code to use ggplot and allow me to view my 8 QQ plots on one page with an appropriate header? Trying the obvious
ggplot(deltaIR.df) + stat_qq(sample = columns[i])
gets me only an error message
Warning: Ignoring unknown parameters: sample
Error: stat_qq requires the following missing aesthetics: sample
and adding in the aesthetics
ggplot(deltaIR.df, aes(column_names)) + stat_qq()
is no better. The error message just changes to
Error: Aesthetics must be either length 1 or the same as the data (5271)
In short, nothing I have done so far (even with Google's assistance) has got me closer to a solution. May I ask for guidance?

I keep getting the same error no matter what from R library rWBclimate

I am trying to use the package "rWBclimate", but nothing works and I keep getting the same error message.
Even when I try running code from the vignette (see code below) I get the same error
(https://cran.r-project.org/web/packages/rWBclimate/vignettes/rWBclimate.pdf).
I have tried several functions and I have fiddled around with the UTF-settings, I have also updated R and all packages to the latest versions...
library(rWBclimate)
usa.dat <- get_model_temp("USA", "mavg", 2080, 2100)
usa.dat.bcc <- usa.dat[usa.dat$gcm == "bccr_bcm2_0", ]
usa.dat.had <- usa.dat[usa.dat$gcm == "ukmo_hadcm3", ]
usa.dat.bcc$ID <- paste(usa.dat.bcc$scenario, usa.dat.bcc$gcm, sep = "-")
usa.dat.had$ID <- paste(usa.dat.had$scenario, usa.dat.had$gcm, sep = "-")
plot.df <- rbind(usa.dat.bcc, usa.dat.had)
ggplot(plot.df, aes(x = as.factor(month), y = data, group = ID, colour =
gcm, linetype = scenario)) + geom_point() + geom_path() + ylab("Average
temperature in degrees C \n between
xlab("Month") + theme_bw()
Error = "No encoding supplied: defaulting to UTF-8.
Error in rep(locator, dim(data_out)[1]) : invalid 'times' argument"
Any suggestions?
Thank you
The encoding is not the problem here, that is not an error message.
When running vignette this is what pops up for me:
No encoding supplied: defaulting to UTF-8.
Error in rep(locator, dim(data_out)[1]) : invalid 'times' argument
The first bit is FYI - R is telling you it defaults to UTF-8.
Check the description file in the package of for example tidyverse, ggplot, caret. You will observe that there is a line reading:
Encoding: UTF-8.
In the description file of the package rWBclimate the encoding is missing which I reckon is prompting R's message.
The second bit is the error and I suspect the issue is with the package itself as a quick glance shows some of the functions are not visible to R, ie. check_ISO_codes() returns an error: could not find function "check_ISO_code". I am not entirely sure if the code is even maintained anymore, there were some questions about its status:
https://github.com/ropensci/rWBclimate/issues/35
If I understand correctly the maintenance was shifted but I am not sure if the package has since been updated in any way.
In any case, hope you get to the bottom of this!

Resources