Closed sarahalmar closed 3 years ago
From what you show, you haven't plotted anything in rgl
. plot
is typically for 2D plotting, not 3D plotting.
If that's not the issue, then please include something reproducible.
I am using the BIGL package and in the vignette code, the steps are to plot with plot, then view3D. (image from: https://cran.r-project.org/web/packages/BIGL/vignettes/analysis.html#fitting-marginal-on-axis-data). I am plotting a list, based on the transformations done, so I was unable to use the plot_3d function.
Image from BIGL CRAN
It's helpful to include code that others can run to help with debugging. I can reproduce your problem with this code, based on the ?plotResponseSurface
example:
library(BIGL)
data <- subset(directAntivirals, experiment == 1)
## Data must contain d1, d2 and effect columns
fitResult <- fitMarginals(data)
data_mean <- aggregate(effect ~ d1 + d2, data = data[, c("d1", "d2", "effect")],
FUN = mean)
## Construct the surface from marginal fit estimates based on HSA
## model and color it by mean effect level
plotResponseSurface(data, fitResult, null_model = "hsa",
colorBy = data_mean, breaks = 10^(c(0, 3, 4, 6)),
colorPalette = c("grey", "blue", "green"))
rglwidget()
I'll see if I can track down the issue to fix it. In the meantime, could you please put together a similarly self-contained version of your example, so that I can test the fix on it? Please don't use images of code, paste your actual code into the comment, so I can cut and paste it myself.
This is the data for plotting the surface plot, i tried plotReponseSurface
as well and I stilll got a black screen. Any help is so greatly appreciated!
library (BIGL)
library(knitr)
library(rgl)
library(ggplot2)
set.seed(12345)
#look at Antiviral Data
data("directAntivirals", package="BIGL")
head(directAntivirals)
tail(directAntivirals)
#subset data to experiment one
subsetData <- function(data, i) {
# want a single experiment
subset(data, experiment == i ) [, c("effect", "d1", "d2")]
}
class(subsetData)
class(data)
dim(data)
i <- 1
data <- subsetData(directAntivirals, i)
#transform the data -- skipped
dim(data)
## Fitting marginal models-- non-linear least squares
marginalFit <- fitMarginals(data, transforms = NULL , method = "nls",
names = NULL)
summary(marginalFit)
class(marginalFit)
rs <- fitSurface(data, marginalFit,
null_model = "loewe",
B.CP = 50, statistic = "none", parallel = FALSE)
plot(rs, legend = FALSE, main = "")
view3d(0, -75)
rglwidget()
`
It seems there are at least two bugs here. I have fixed the first one, but I'm still seeing some problems.
I believe you can avoid the bug that I've fixed by changing your last line to rglwidget(minimal = FALSE)
, but when I do only that, I don't see the points or text or axes. I'll keep going and see what's going wrong.
Thank you so much, I appreciate it! I will try different ways of plotting within rgl package using the list from the fitsurface modeling.
I've sort of worked out the conditions for the second bug, but haven't found it yet. It seems to require a background image (which plotResponseFunction
uses to display the title and legend if you had one) and objects with lit = FALSE
. Unfortunately, you can't avoid those two things in the BIGL
plotting function, but if you're putting together your own plot, for now you should. I'm not sure why that particular combination should trigger problems, but apparently it does.
I'll probably locate the exact cause soon, but not likely before tomorrow.
ok, thank you so much for looking into this. For now, I have tried to plot the rs (list) data but since it is not a dataframe. I am unable to use the plot3D function. I have a presentation tmw and would like to show 3D plot of combination drug effects using a similar method to BIGL but I am not sure which would work.
I've made a small change to the plotResponseSurface
function which should get you through your presentation. It won't draw a legend or title now, but should work with rglwidget()
. You can install this version using
remotes::install_github("dmurdoch/BIGL")
Let me know if there are other problems.
Thanks, I have tried running it a few times, but I still only get a black screen when calling the rglwidget()
for the plotResponseSurface
. I am not sure if I should change the options when calling the rgl
. A few suggestions online stated to use options(rgl.printRglwidget = TRUE)
but that still did not seem to work.
When I turned the rglwidget(minimal = FALSE)
I do get a plot (picture 2) but without axis, like you had mentioned. In terms of the legend or title, that is fine for now but I would just like to plot the points and be able to view the 3D surface plot.
Here is the code with your version installed:
library(BIGL)
remotes::install_github("dmurdoch/BIGL")
data <- subset(directAntivirals, experiment == 1)
## Data must contain d1, d2 and effect columns
fitResult <- fitMarginals(data)
data_mean <- aggregate(effect ~ d1 + d2, data = data[, c("d1", "d2", "effect")],
FUN = mean)
## Construct the surface from marginal fit estimates based on HSA
## model and color it by mean effect level
plotResponseSurface(data, fitResult, null_model = "hsa",
colorBy = data_mean, breaks = 10^(c(0, 3, 4, 6)),
colorPalette = c("grey", "blue", "green"))
rglwidget()
plot(rs, legend = FALSE, main = "")
view3d(0, -75)
rglwidget(minimal = FALSE)
Picture 1:
Picture 2:
On 03/03/2021 10:57 p.m., sarahalmar wrote:
Thanks, I have tried running it a few times, but I still only get a black screen when calling the |rglwidget()| for the |plotResponseSurface|. I am not sure if I should change the options when calling the |rgl|. A few suggestions online stated to use |options(rgl.printRglwidget = TRUE)| but that still did not seem to work.
You'll still need the other suggestion, i.e. use rglwidget(minimal = FALSE) as well as the BIGL change.
I have tried to plot with the rglwidget by running the vignette source code but only a black box appears. I have tried to produce a 3D plot using the rgl iris vignette data and I was able to using plot_3D, however since the code here is not a dataframe, I cannot use that. I am not sure why only a black box appears in the viewer. I have tried knitting it in RMarkdown but it still does not appear.
Any help is appreciated. I run my R code through a Domino workspace with R 3.6.