ggpubr ,ggpp, ggformula functions not working with ggplotly - r

I am using a few functions from ggpubr and ggpp to draw my plots.
Specifically, i am using the functions: geom_quadrant_lines(), stat_quadrant_lines(), geom_lm, stat_regline_equation in my plot.
However, when i convert my ggplot2 object into a plotly object using ggplotly(), the above dont seem to be working.
Is there any workaround? Adding the geoms to the plotly object also dont seem to work
Example Code and Errors Below:
library(ggplot2)
library(plotly)
library(ggpubr)
library(ggpp)
library(ggformula)
set.seed(1234)
data <- data.frame(x = -5:4 + runif(10,-1,1), y = seq(-15,12,3)-runif(10,-1,1)*2)
head(data)
g <- ggplot(data = data, aes(x=x, y=y)) +geom_point() +
stat_mean(color = "blue") +
geom_quadrant_lines()+
stat_quadrant_counts()+
stat_regline_equation( formula = y~x, aes(label = paste( ..eq.label.., ..adj.rr.label.., sep="~~")),output.type="expression", label.y.npc = 0.8, label.x.npc = 0.0, colour="black", size = 2.5) +
labs(title= "Example Plot") + #change the number of days here
geom_lm(interval = "prediction", level = 0.95)
g
p <- ggplotly(g)
p
p %>% geom_lm(mapping = aes(x=x, y=y), data = data, interval = "prediction", level = 0.95)
The ggplot2 output is
Once converted into plotly object using ggplotly, it becomes
I also get the below warning messages
> p <- ggplotly(g)
Warning messages:
1: In geom2trace.default(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]]) :
geom_GeomQuadrantLines() has yet to be implemented in plotly.
If you'd like to see this geom implemented,
Please open an issue with your example code at
https://github.com/ropensci/plotly/issues
2: In geom2trace.default(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]]) :
geom_GeomTextNpc() has yet to be implemented in plotly.
If you'd like to see this geom implemented,
Please open an issue with your example code at
https://github.com/ropensci/plotly/issues
3: In geom2trace.default(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]]) :
geom_GeomLm() has yet to be implemented in plotly.
If you'd like to see this geom implemented,
Please open an issue with your example code at
https://github.com/ropensci/plotly/issues

Related

Why does ggplotly break when ggtern is loaded?

I was hoping to use plotly::ggplotly() to plot a graph produced with ggtern() with a tooltip feature. But loading the package ggtern caused ggplotly to throw the following error:
Error in inherits(theme[[element]], ggplot_global$element_tree[[element]]$class) :
'what' must be a character vector
What's more, this error appears for all graphs, not just those produced by ggtern.
Here is an example.
library(ggplot2)
# This works
gg.mtcars <- ggplot(mtcars, aes(hp, mpg)) +
geom_point()
plotly::ggplotly(gg.mtcars)
library(ggtern)
data("Feldspar")
gg.feldspar <- ggtern(data = Feldspar, aes(x = Ab, y = An, z = Or)) +
geom_point()
# This throws an error
plotly::ggplotly(gg.feldspar)
# And now this throws an error too
plotly::ggplotly(gg.mtcars)

Converting ggplot graph with ggplotly function

I have got a shiny application where I use the plotly package to convert my ggplot graph into dynamics graphics.
I am at the moment facing a problem with this conversion.
Here is my data.frame :
b <- data.frame(ID_Miseq = c(rep("P1",8), rep("P2",8), rep("P3",8), rep("P4",8)),
Condition1 = c(rep("A", 8), rep("B",16), rep("C", 8)),
Taxon = c(rep(paste0("T",1:8),4)),
Percent = sample(seq(1,25,0.1),32))
When I am creating my static barplot, no problem.
library(ggplot2)
gg <- ggplot(b, aes(x = ID_Miseq, y = Percent, fill = Taxon))
gg <- gg + geom_bar(stat = "identity", position = "stack")
factors <- "~Condition1"
gg <- gg + facet_grid(factors, scales = "free", space = "free_x")
gg
But, when I am using the ggplotly function from the plotly package, one of the sample is turning into numeric scale.
library(plotly)
ggplotly(gg)
Does anyone have ever faced the same kind of issue ? Am I using the ggplotly function wrong ? I am using plotly 4.7.1
Thanks, this is now fixed in the dev version, https://github.com/ropensci/plotly/commit/a0fc9c93e3b64ef4545b3522abbdfe44dc0e81a3
Install the dev version with devtools::install_github("ropensci/plotly")

Error ggplot and ggQC: No geom called label in R with KNIME

Here my problem, i use library ggplot2 for displaying a graph which use quality control charts.
I'm using Knime, precisely R snippet for using my code. When i evaluate my script with R snippet Knime, I have this error : Error : No geom called label
This is an extract of my code in R snippet Knime :
library(ggplot2)
Test <-knime.in
require(ggQC)
require(ggplot2)
p <- ggplot(Test, aes(x=Day, y=Temperature)) +
ggtitle("XmR chart Temperature(°C)")+
xlab("Day")+
ylab("Temperature(°C)")+
stat_summary(fun.y = "mean", color = "blue", geom = c("point")) +
stat_summary(fun.y = "mean", color = "blue", geom = c("line")) +
stat_QC_labels(method = "XmR") + # label the QC lines
stat_QC(method = "XmR")
print (p)
This is the data in knime.in :
After several tests, i found the problem which come from ggQC package, precisely this part of this code :
stat_QC_labels(method = "XmR") + # label the QC lines
stat_QC(method = "XmR")

crosstalk and plotly - ggplotly does not accept shareddata-object

I've been trying to generate interactive linked visualizations with by use of the plotly and crosstalk libraries. As shown in the example below, it seems to be possible to pass ggplot2 a 'shared Dataframe'-Object in order to generate linked views with ggplotly(). When i try to run this example i get the following error-message:
Error: ggplot2 doesn't know how to deal with data of class SharedData/R6
I'm using the current versions of ggplot2 (v. 2.2.1) and plotly (4.5.6). What can cause this error?
Thx for help!
The example which i'm trying to replicate can be found here:
https://cpsievert.github.io/plotly_book/linking-animated-views.html
library(gapminder)
library(crosstalk)
library(ggplot2)
library(plotly)
g <- crosstalk::SharedData$new(gapminder, ~continent)
gg <- ggplot(g, aes(gdpPercap, lifeExp, color = continent, frame = year)) +
geom_point(aes(size = pop, ids = country)) +
geom_smooth(se = FALSE, method = "lm") +
scale_x_log10()
ggplotly(gg) %>%
highlight("plotly_hover")
Error: ggplot2 doesn't know how to deal with data of class SharedData/R6

removing a layer legend in ggplot

Another ggplot legend question!
I have a dataset of the form
test <- data.frame(
cond = factor(rep(c("A", "B"), each=200)),
value = c(rnorm(200), rnorm(200, mean=0.8))
)
So two groups and some values and I want to plot the density. I also want to add a line indicating the mean for each group to the plot so I:
test.cdf <- ddply(test, .(cond), summarise, value.mean=mean(value))
Then in ggplot call:
ggplot(test, aes(value, fill=cond)) +
geom_density(alpha=0.5) +
labs(x='Energy', y='Density', fill='Group') +
opts(
panel.background=theme_blank(),
panel.grid.major=theme_blank(),
panel.grid.minor=theme_blank(),
panel.border=theme_blank(),
axis.line=theme_segment()
) +
geom_vline(data=test.cdf, aes(xintercept=value.mean, colour=cond),
linetype='dashed', size=1)
If you run the above code, you get a legend indicating each group, but also one for the mean indicator vline. My question is how can I get rid of the legend for the geom_vline()?
Depending on the version of ggplot2 you are using you get this problem. Using ggplot2 vs 0.9.0 on R2.14.1 I get this graph:
which does not include the legend for the vline. In this version of ggplot2 you can tweak the occurence of the legend using show_guide:
ggplot(test, aes(value, fill=cond)) +
geom_density(alpha=0.5) +
labs(x='Energy', y='Density', fill='Group') +
opts(
panel.background=theme_blank(),
panel.grid.major=theme_blank(),
panel.grid.minor=theme_blank(),
panel.border=theme_blank(),
axis.line=theme_segment()
) +
geom_vline(data=test.cdf, aes(xintercept=value.mean, colour=cond),
linetype='dashed', size=1, show_guide = TRUE)
which reproduces your problem. Default, show_guide = FALSE. In older versions, you can add legend = FALSE to geom_vline in order to omit the legend. Adding legend = FALSE still works still works in the current version, but it throws a warning:
Warning message:
In get(x, envir = this, inherits = inh)(this, ...) :
"legend" argument in geom_XXX and stat_XXX is deprecated. Use show_guide = TRUE or show_guide = FALSE for display or suppress the guide display.
I would recommend upgrading ggplot2.

Resources