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

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!

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?

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?

mosaic()-function of the vcd package: error in adding text in the cells

I have created a mosaic plot using mosaic function in the vcd package. Now I wish to add some annotations using labeling_cells. Unfortunately, I get an error. The problem might be that it is not the standard Titanic example...
library("grid"); library("vcd")
dataset <- read.table("http://bit.ly/1aJTI1C")
# prepare data for plot as a "Structured Contingency Table"
data1 <- structable(dauer ~ groesse + ort, dataset)
# basic plot
mosaic(data1,
# separate the two elements of the plot
split_vertical = c(T, T, F),
# put the names in the right places and adds boxes
labeling_args = list(tl_labels = TRUE,
tl_varnames = FALSE,
boxes = TRUE),
# grip remains open
pop=FALSE
)
# structure that matches plot, but it does not help
#match<-t(data1)
# try to add labels
labeling_cells(text = data1, clip = FALSE)(data1)
This results in:
# Error in ifelse(abbreviate_varnames, sapply(seq_along(dn), function(i) abbreviate(dn[i], :
# replacement has length zero
# In addition: Warning message:
# In rep(no, length.out = length(ans)) :
# 'x' is NULL so the result will be NULL
Another problem I have is that the boxes do not fit the labels. If you have a hint for that just let me know as well!
It's my first question here, so please excuse potential errors!
Thanks a lot!
Fixed upstream in vcd 1.4-4, but note that you can simply use
mosaic(data1, labeling = labeling_values)
Yes, this is quite confusing and ought to be fixed in labeling_cells(). For some reason the data in the labeling should be a regular table, not a structable. I'll raise this with David, the principal author of mosaic() and package maintainer.
If you know it it's easy to work around it, though:
labeling_cells(text = as.table(data1), clip = FALSE)(as.table(data1))

r - Add text to each lattice histogram with panel.text but has error "object x is missing"

In the following R code, I try to create 30 histograms for the variable allowed.clean by the factor zip_cpt(which has 30 levels).
For each of these histograms, I also want to add mean and sample size--they need to be calculated for each level of the factor zip_cpt. So I used panel.text to do this.
After I run this code, I had error message inside each histogram which reads "Error using packet 21..."x" is missing, with..." (I am not able to read the whole error message because they don't show up in whole). I guess there's something wrong with the object x. Is it because mean(x) and length(x) don't actually apply to the data at each level of the factor zip_cpt?
I appreciate any help!
histogram(~allowed.clean|zip_cpt,data=cpt.IC_CAB1,
type='density',
nint=100,
breaks=NULL,
layout=c(10,3),
scales= list(y=list(relation="free"),
x=list(relation="free")),
panel=function(x,...) {
mean.values <-mean(x)
sample.n <- length(x)
panel.text(lab=paste("Sample size = ",sample.n))
panel.text(lab=paste("Mean = ",mean.values))
panel.histogram(x,col="pink", ...)
panel.mathdensity(dmath=dnorm, col="black",args=list(mean=mean(x, na.rm = TRUE),sd=sd(x, na.rm = TRUE)), ...)})
A discussion I found online is helpful for adding customized text (e.g., basic statistics) on each of the histograms:
https://stat.ethz.ch/pipermail/r-help/2007-March/126842.html

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

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

Resources