I am trying to combine a two plotly figures (type = 'mesh3d' and type = 'scatter3d'). Each of the single plots is perfectly fine without any warning. After I use subplot a warning occurs every time I try to display the plot.
warning 'layout' objects don't have these attributes: 'NA'
I have tried to suppressWarning but this does not have any effect.
Any ideas what I am missing here to get rid of the warning?
Plotly Version: 4.9.3
R Version: 4.0.1
# plot data
plt_data <- data.frame(maturity=rep(1:10, each=10),
tenor=rep(1:10, 10),
value=rnorm(100))
# plot 1
fig11 <- plot_ly(
data=plt_data, x=~maturity, y=~tenor, z = ~value,
type = "mesh3d",intensity = ~value,
colors = colorRamp(c(
rgb(168, 191, 173, max = 255),
rgb(100, 181, 117, max = 255),
rgb(0,100,80, max = 255)
)),
contour=list(show=T, width=4, color="#fff"),
showscale = F,
scene='scene1',
lighting = list(ambient = 0.9),
hoverinfo="skip",
source="myID"
)
# plot 2
fig12 <- plot_ly(
data=plt_data, x=~maturity, y=~tenor, z = ~value,
type = "scatter3d",
mode="markers",
hovertemplate="Maturity: %{x:.f}<br>Tenor: %{y:.f}<br>Value: %{z:.4f}<extra></extra>",
marker=list(
symbol="square-open",
size=4,
color="#3d543f"
),
scene='scene1',
source="myID",showlegend=F
)
# subplot which does throw a warning
subplot(fig11, fig12)
For R and Shinyapps, to suppress warnings like this:
options(warn = -1)
There is an open issue regarding the warning. Here's a workaround to hide the warnings for this case -
function_to_hide_plotly_warning <- function(...) {
plot <- subplot(...)
plot$x$layout <- plot$x$layout[grep('NA', names(plot$x$layout), invert = TRUE)]
plot
}
function_to_hide_plotly_warning(fig11, fig12)
I am trying to save a plot as png in R, but when I use Arabic letters in plot the saved plot doesn't have any good structure?
ds <- data.frame(labels = c("سامان", "احمد", "یوسف","A1", "B2", "C3"),values = c(10, 40, 60,50,40,10))
p=plot_ly(ds, labels = ds$labels, values = ds$values, type = "pie")
plotly::orca(p, file="p.png")
I'm trying to get familiar with plotly's functionality and syntax and have tried several of the scripts provided to compose and render plots of data. However, when generating the plotly output using RStudio I'm getting the following error: "Warning message:
Specifying width/height in layout() is now deprecated.
Please specify in ggplotly() or plot_ly()"
The output image appears jumbled and uninterpretable in the RStudio console and I've tried a few changes like setting the plotly object's width and height equal to null etc without luck.
Here is one of the sample scripts I've used when experiencing this issue:
library(plotly)
trace1 <- list(
x = c("Aug-12", "Sep-12", "Oct-12", "Nov-12", "Dec-12", "Jan-12", "Feb-13", "Mar-13", "Apr-13", "May-13", "Jun-13", "Jul-13"),
y = c(65, 77, 112, 279, 172, 133, 152, 106, 79, 225, 99, 150),
hoverinfo = "x+y+name",
line = list(
color = "#5BC075",
width = "3"
),
mode = "lines",
name = "Median deal size",
type = "scatter",
uid = "a8e83b",
xsrc = "jackluo:508:b357d2",
ysrc = "jackluo:508:d19900"
)
trace2 <- list(
x = c("Aug-12", "Sep-12", "Oct-12", "Nov-12", "Dec-12", "Jan-12", "Feb-13", "Mar-13", "Apr-13", "May-13", "Jun-13", "Jul-13"),
y = c(116, 125, 126, 125, 244, 136, 80, 82, 89, 82, 95, 107),
hoverinfo = "x+y+name",
line = list(
color = "#CC6E55",
width = "3"
),
mode = "lines",
name = "Number of deals",
type = "scatter",
uid = "2be33b",
xsrc = "jackluo:508:b357d2",
ysrc = "jackluo:508:5d533d"
)
data <- list(trace1, trace2)
layout <- list(
autosize = TRUE,
font = list(
family = "Overpass",
size = 12
),
height = 720,
legend = list(
x = 0,
y = -0.1,
bgcolor = "rgba(255, 255, 255, 0)",
orientation = "h"
),
margin = list(
r = 40,
t = 40,
b = 40,
l = 40,
pad = 2
),
title = "",
width = 1280,
xaxis = list(
autorange = TRUE,
nticks = 12,
range = c(0, 11),
rangemode = "tozero",
type = "category"
),
yaxis = list(
autorange = TRUE,
range = c(0, 293.6842105263158),
rangemode = "tozero",
type = "linear"
)
)
p <- plot_ly()
p <- add_trace(p, x=trace1$x, y=trace1$y, hoverinfo=trace1$hoverinfo, line=trace1$line, mode=trace1$mode, name=trace1$name, type=trace1$type, uid=trace1$uid, xsrc=trace1$xsrc, ysrc=trace1$ysrc)
p <- add_trace(p, x=trace2$x, y=trace2$y, hoverinfo=trace2$hoverinfo, line=trace2$line, mode=trace2$mode, name=trace2$name, type=trace2$type, uid=trace2$uid, xsrc=trace2$xsrc, ysrc=trace2$ysrc)
p <- layout(p, autosize=layout$autosize, font=layout$font, height=layout$height, legend=layout$legend, margin=layout$margin, title=layout$title, width=layout$width, xaxis=layout$xaxis, yaxis=layout$yaxis)
p$x$layout$width <- NULL
p$x$layout$height <- NULL
p$width <- NULL
p$height <- NULL
p
Any help resolving this issue so charts are correctly scaled and legible would be much appreciated!
As #NoahOlsen suggested, you need to format your x-axis values as a date.
trace1$x <- as.Date(paste0("01-", trace1$x), format = "%d-%b-%y")
trace2$x <- as.Date(paste0("01-", trace2$x), format = "%d-%b-%y")
Explanation
as.Date() tries to format an input into a date object. It works well with ISO date strings (e.g., 2019-04-21), but needs some help with more tricky formats.
From ?strptime:
%d - Day of the month as decimal number (01–31).
%b - Abbreviated month name in the current locale on this platform. (Also matches full name on input: in some locales there are no abbreviations of names.)
%Y - Year with century. Note that whereas there was no zero in the original Gregorian calendar, ISO 8601:2004 defines it to be valid (interpreted as 1BC): see https://en.wikipedia.org/wiki/0_(year). Note that the standards also say that years before 1582 in its calendar should only be used with agreement of the parties involved. For input, only years 0:9999 are accepted.
Furthermore, we also need a specific day of the month. As it does not exist in your data, I added 01- via paste0() to every value of the date vector. Other values, such as 15-, would also have been a valid choice (depending on your data and what type of output you expect). This way, we can make the function recognize your date via format = "%d-%b-%y".
Check out ?as.Date and ?strptime for more information. Ping me if you require further guidance. Happy to help.
It looks like your X axis is a character rather than a date so the axis is sorted alphabetically rather than chronologically. I would try making the x values dates.
Using VennDiagram package I'm generating two graphs in the following manner:
# First graph
VennDiagram::draw.pairwise.venn(
area1 = 100,
area2 = 70,
cross.area = 30,
category = c("A1", "B1"),
fill = c("#00204DFF", "#FFEA46FF")
) -> vg1
# Second graph
VennDiagram::draw.pairwise.venn(
area1 = 120,
area2 = 80,
cross.area = 10,
category = c("A2", "B2"),
fill = c("#000004FF", "#FCFFA4FF")
) -> vg2
When called via grid::grid.draw(vg1) and grid::grid.draw(vg2) the charts show as expected:
grid::grid.draw(vg1)
grid::grid.draw(vg2)
Question
How can I create one grid object where both plots are placed one under another?
Attempt
grdFrme <- grid::grid.frame(name = "gf")
grid::grid.pack("gf", vg1)
Error in packGrob(grid.get(gPath), grob, side, row, row.before,
row.after, : invalid 'grob'
Desired results
One solution could be to use awesome multipanelfigure package (fill the panels with base, 'lattice', 'ggplot2' and 'ComplexHeatmap' plots, grobs, and PNG, JPEG, SVG and TIFF images).
library(multipanelfigure)
figure <- multi_panel_figure(columns = 1, rows = 2)
figure %<>%
fill_panel(vg1) %<>%
fill_panel(vg2)
I am trying to create the simplest of scatter charts using dimple and rCharts. I am curious if there is something I mis-understand about the 'scatter' type. When I run this code, the y-axis values are off by factors of ten or larger--almost as if the scatter chart is acting as a stacked bar chart instead of a simple scatter plot. The sample data below mimics my data exactly.
testdat1 <- data.frame(Recommend = sample(60:90, 200, replace = T), Quiet = sample(20:60, 200, replace = T),
Owner = as.factor(rep(c(1,2), 100)))
summary(testdat1) # no values exceed 90
dtest <- dPlot(Recommend ~ Quiet, groups = 'Owner', data = testdat1, type = 'scatter')
dtest # plotted y-values reach upwards of 450
Any thoughts?
See comment but answer might be accomplished through this block of code:
require(rCharts)
testdat1 <- data.frame(Recommend = sample(60:90, 200, replace = T), Quiet = sample(20:60, 200, replace = T),
Owner = as.factor(rep(c(1,2), 100)))
summary(testdat1) # no values exceed 90
dtest <- dPlot(Recommend ~ Quiet, groups = 'Owner', data = testdat1, type = 'bubble')
#will aggregate as avg by default
dtest$xAxis(type="addMeasureAxis")
dtest
#add x,y, and grouping so now only will aggregate where x,y,and group is exact same
#if still a problem, could a unique id and group on that
dtest$params$groups <- c('Recommend','Quiet','Owner')
dtest # plotted y-values reach upwards of 450