I am trying to improve the display of a survfitr plot (as per the link below), with absolutely no luck. I get the impression I may have to redefine the plot function from scratch given I can't even change the xlab/ylab arguments without throwing warnings.
https://www.rdocumentation.org/packages/survrec/versions/1.2-2/topics/plot.survfitr
I would like my survfitr object to be displayed like a singular event survival curve using with the ggsurvplot function. A good example can be seen here:
http://www.sthda.com/english/wiki/survival-analysis-basics
Any suggestions?
Code I have tried:
plot(surfvitrResult, conf.int=TRUE, prob=FALSE, xlim=c(0,xMax), ylim=c(0,yMax))
When I try to add in xlab or ylab I get a "formal argument xlab" warning; I understand why this is happening, that's not my issue. I would like the survfitr object to be plotted similar to its singular survfit object as per the link above and screen grabbed here:
Related
A seemingly simple question,
How can I plot the "score" in the "Pac-Man" model in NetLogo
I have tried the obvious approaches (adding a Plot to the interface, telling it to "plot score").
The problem I seem to be having is that the variable for “score” in the Pac-Man game isn’t returning a value to the plot - however it is returning a value elsewhere in the program (the "Score" monitor at the top of the model.
More info available here: https://ccl.northwestern.edu/netlogo/models/Pac-Man
(though you won't be able to add the new Plot)
Short answer: after adding your plot, add update-plots to the top of the play procedure. Like this:
to play ;; Observer Forever Button
update-plots
;; Only true at this point if you died and are trying to continue
if dead?
...
Normally in NetLogo plotting seems to happen automatically because most models are tick-based, and they rely on calling tick in a go procedure to update the plots. This model is not tick-based, which is perfectly fine, but then we have to add the call to update-plots explicitly while it runs to get our plots updating.
I am trying to plot a graph of certain values against time using the plot function.
I am simply trying to change the representation of the dots, using the pch= function. However R is simply ignoring me! I have also tried removing the dots so that I can place labels instead, but when I type in type="n" it ignores that too!
I am using the exact same format of code that I have used for other plots but this time it just isn't cooperating.
If I specify other features such as the title or the x/y axis labels, it will add those in but it simply ignores the pch or type commands.
This is my basic code:
plot(Differences ~ Time, data=subsetH)
But if I run
plot(Differences ~ Time, type="n", data=subsetH)
or
plot(Differences ~ Time, pch=2, data=subsetH)
it keeps plotting the same thing.
Is there something obvious I have missed?
I just came across your question because I encountered the same thing - creating an empty plot did not work, as type='n' was always ignored (as well as other type specifications).
With the help of this entry: Plotting time-series with Date labels on x-axis
I realized that my date format needed to be assigned as "date" class (as.Date()).
I know your entry dates back a little bit already, but maybe it's still useful.
I was using the following code to plot a spatial plot successfully:
colours<-(brewer.pal(7, "Blues"))
brks<-classIntervals(EDdata2$SIRt, n=7, style="fixed",fixedBreaks=c(0,1,2,5.0,10.0,20,50,120))
plot(brks, pal=colours)
brks<-brks$brks
plot(EDdata2, col=colours[findInterval(EDdata2$SIRt, brks,
all.inside=TRUE)], axes=F, border=FALSE)
However I made some changes to the spatialpolygonsdataframe EDdata2 by adding some extra columns and changing how SIRt is calculated (however it remains a column of numbers - they are just calculate differently)
Now when I try to run the plot code I get an error despite having made no changes to the plotting code:
Error in plot.default(...) : formal argument "axes" matched by multiple actual arguments
Whats going on here ?
That means that the package author of the unnamed package you used to create EDdata2 defined a plot method for whatever class EDdata2 might be that both used the axes argument and also used the triple dot mechanism to pass arguments to plot.default without filtering out that argument. (This does suggest that the package author didn't really want you to make your own axes, so you should investigate the help page for plot.whatever to see if it offers a mechanism for passing the values you want to use for 'at' and 'labels'.) You will need to do the spadework yourself (or edit your answer to make it more complete and reproducible) to investigate.
If this code is using the plot method for the SpatialPolygons-class in package:sp then the default value for axes is already FALSE.
help("SpatialPolygons-class", package="sp")
It is of course possible to mess this up by defining "F" to be something other than "FALSE" and then using axes=F. In the current instance it might be simpler to just remove that argument from the call.
I'm trying to plot a cox proportional hazard model in R. (or a logit model)
I used the following code (which I copied from https://sites.google.com/site/daishizuka/toolkits/plotting-logistic-regression-in-r)
c<-coxph(formula=Surv(year, promo)~prov.yrs, data=cul)
curve(predict(c, data.frame(prov.yrs=x), type="risk"), add=TRUE)
I get the error message
Error in plot.xy(xy.coords(x, y), type = type, ...) :
invalid graphics state
I believe there is something wrong with plotting this, so I was wondering if there is a way to plot this. I get the same error message when I use glm. Any help will be appreciated!!
The example you copied from shows a logistic regression, but you are fitting a coxph model, they are very different in how they are handled.
If you just want a plot of the the hazard ratio then your code will basically work (except you are adding to a plot that is not there, which may be what generates the error, try changing add to FALSE).
If you want to plot the survival curve(s) then use the survfit function to get the predicted survival information and plot that.
The error message suggests you did not have a device open or perhaps there was some other problem with the plot you were trying to add to? That code produces a plot over a range input [0,1] with a toy example I built from the coxph help page. Perhaps your range for the 'prov.yrs' is different than an existing plot, or there is no device open? Try plot.new(), plot whatever else you were going to use, and then rerun? (The add=TRUE will suppress plotting of the box, axes and labels.)
I'm creating a plot and adding a basic loess smooth line to it.
qplot(Age.GTS2004., X.d18O,data=deepsea, geom=c('point')) +
geom_smooth(method="loess",se=T,span=0.01, alpha=.5, fill='light blue',color='navy')
The problem is that the line is coming out really choppy. I need more evaluation point for the curve in certain areas. Is there a way to increase the number of evaluation points without having to reconstruct geom_smooth?
Use the n parameter, as documented in stat_smooth.
Hadley: The documentation leads people astray. geom_smooth does not document that it accepts parameters on behalf of stat_smooth, nor is there any link on that page to stat_smooth for continued reading.
I figured the parameter was buried on some other help page, but I landed here to clue in where.