plot() and dev.off() error message for forestplot() - r

I've made a figure using forestplot() and I've tried to output it as a high resolution figure but it's not working. The figure plots fine in the R studio plots window, but when I try to use plot() and dev.off() I get an error message.
No idea why.
Thanks for any help!
setwd("C:/Users/User/Desktop")
ppi <- 300
png("plotfp.png", width=9*ppi, height=9*ppi, res=ppi)
plot(plotfp)
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' is a list, but does not have components 'x' and 'y'
> dev.off()

Related

Getting weird error with the function as.ggplot() from ggplotify package

This uses the library ggplotify. This allows me to take a base r plot and create a ggplot plot from it with the function as.ggplot().
However, I am receiving an error that doesn't make sense to me when I run the following lines of code.
y <- 1:10
x <- 2:11
length(x)
length(y)
as.ggplot(~plot(x, y))
The error I receive is:
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' and 'y' lengths differ.
However, x and y have the same length and when I use plot(x,y) normally, I don't receive any errors. Can someone please explain this to me? Thanks in advance!
It works when you put the values directly in the function:
as.ggplot(~plot(1:10,2:11))
I think it is just limited to working like this.

Error with plotly subplot: Error in xy.coords(x, y) : 'x' is a list, but does not have components 'x' and 'y'

I am getting an error when trying to use plotly subplot in R and I cannot figure out why. If I try to plot two plotly plots b and c:
library(plotly)
df <- data.frame("A"=1:10, "B"=11:20, "C"=21:30)
b_plot <- plot_ly(df) %>%
add_trace(x=~A, y=~B)
c_plot <- plot_ly(df) %>%
add_trace(x=~A, y=~C)
they work fine by themselves but when I try to plot them side by side in a subplot:
p <- subplot(b_plot, c_plot)
I get the error:
Error in xy.coords(x, y) : 'x' is a list, but does not have components 'x' and 'y'
I can't even get the Plotly example to work. Any help appreciated, thanks!
Turns out the function was being overwritten by the subplot function from the Hmisc package so changing to plotly::subplot(...) fixes the problem

Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' is a list, but does not have components 'x' and 'y'

I try to plot the variogram in R. When I run the below code:
library(geoR)
Data = as.geodata(Data2, coords.col=1:2, data.col=3)
VG = variog(Data2,estimator.type="classical")
VG.fit = variofit(VG, ini.cov.pars =c(0.095,1.4), cov.model="gaussian", fix.nugget=FALSE, nugget=0.065)
plot(VG.fit)
I am getting an error:
Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' is a list, but
does not have components 'x' and 'y'
In this case, VG is of class variogram while VG.fit is of classes variomodel and variofit. There is a plot method for variogram, but not for variomodel or variofit. After reading some documentation, it seems that you should plot the variogram first:
plot(VG)
lines(VG.fit)
If you only want the fitted line, then add pch = "" to the plot function as an argument.

R : Plot many boxplot in the same graph using dataframe

Hello everyone and thank you for helping me with R.
i have a 39cols * 168rows matrix which looks like this :
and i want to plot boxplot (1 for each row) in the same graph.
Two hours of intense research on how to make that and i still have no clue.
What i tried (f is the read.csv i got ) :
boxplot(x = as.list(as.data.frame(f)))
qp <- boxplot(x = as.list(as.data.frame(f)))
rn <- as.numeric(rownames(f))
plot(qp,rn)
and i've got :
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' and 'y' lengths differ
even if i do not know if the result of the plot was the thing i wanted.
If you want one box per row, you need to transpose the matrix before passing it to boxplot:
boxplot(t(f))
This will then do the right thing — provided you’ve read in your data correctly. In your image, this isn’t the case: the header columns are (incorrectly) part of the data. Be sure to pass header = TRUE to your data reading function to fix this.

Manipulate graphics within an R package (eRm)

I am using the eRm package to run the dichotomous Rasch model. My problem is that I can not manipulate the length of the x axis on the person-item map.
The description for the plotPImap command says to use xrange= to specify the range, but when I do so, I get the following error:
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' and 'y' lengths differ
Here is my code:
Model2 <- RM(EBL_MC)
plotPImap(Model2, xrange=c(-5:5), latdim = "Writing Achievement", main="Person-Item Map (EBL)")
Suggestions?
This is just a shot in the dark, since you haven't provided a reproducible example, but generally when functions in R ask for an axis range argument, they are looking for only two values, the low and high. Try xrange = c(-5,5).

Resources