I have found that if I mix calls to ggplot and ggplotly together, only the last chart appears and overwrites the others or in some cases blocks the display of subsequent charts. I need to be able to produce some charts with ggplot and others with the interactive ggplotly.
Has anyone encountered this problem? Is there a way to perhaps reset the plot mechanism in RStudio without wiping out all of the plots (e.g., NOT dev.off())?
library("ggplot2")
library("plotly")
test_data <- data.frame(A = c(1,5,7,4,2),
B = c(3,3,6,8,4),
C = c(6,2,9,4,5))
my_dates <- as.Date(c("2010-01-01", "2010-02-01",
"2010-03-01", "2010- 4-01",
"2010-05-01"))
xts_data <- xts(test_data, order.by = my_dates)
p <- autoplot(xts_data, facets = NULL) +
guides(color = guide_legend(override.aes = list(size = 2))) +
geom_line(size = 1)
print(ggplotly(p))
new_df <- data.frame(P = c(70, 70, 70),
Category = c("A", "B", "C"),
Value = c(5, 15, 10))
p <- ggplot(data = new_df, aes(
x = Category, y = Value)) +
geom_bar(position = position_dodge(), stat = "identity")
print(p)