标签: r-plotly

在 >4.x Plotly 中排列线图的路径顺序

我需要绘制一条路径,该路径并不严格从左到右,而是在 y 轴上交叉,但是自从我升级到plotly 4.7以来,我不能不这样做。fx 没问题。3.6

有谁知道如何以情节方式告诉路径如何排序?

library(dplyr)
library(plotly) # > 4.x

data.frame(x = c(1:5,5:1),y = c(1:10)) %>%
  arrange(y) %>%
  plot_ly(x = ~x,y = ~y) %>% add_lines()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

如果你查看 data.frame 它应该遵循红色路径:

data.frame(x = c(1:5,5:1),y = c(1:10)) %>% arrange(y)
   x  y
1  1  1
2  2  2
3  3  3
4  4  4
5  5  5
6  5  6
7  4  7
8  3  8
9  2  9
10 1 10
Run Code Online (Sandbox Code Playgroud)

plot r linechart plotly r-plotly

5
推荐指数
1
解决办法
759
查看次数

离线导出plotly为网页而不包含plotly JS?(R ggplot2)

我知道要在 python 中导出,另一个堆栈交换帖子说:

plotly.offline.plot(data, include_plotlyjs=False, output_type='div')
Run Code Online (Sandbox Code Playgroud)

R有这样的东西吗?

当我另存为网页时,它是一个充满 JavaScript 的大文件。

我想使用他们的 javascript

<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
Run Code Online (Sandbox Code Playgroud)

然后有一个小div id或无论你怎么称呼它。

做这个的最好方式是什么?

编辑:我知道它可以导出为 HTML,但这些 HTML 文档很大(3 兆字节或更多),因为它们包含 javascript。有没有办法在没有plotly javascript的情况下导出它们,然后只使用上面的CDN脚本来调用javascript?

html javascript r plotly r-plotly

5
推荐指数
0
解决办法
1183
查看次数

在 R Plotly 中使用曲面椭圆绘制 Ellipse3d

与这里的问题类似,但这并没有准确地给出我需要的东西,而且我无法弄清楚:Plot ellipse3d in R plotly? 。我想在绘图中重新创建 rgl 的 ellipse3d 和表面椭球体。我知道有一个答案允许绘制椭圆体,但作为单独的不透明标记,我需要将其作为稍微不透明的表面椭球体,以便我仍然可以看到椭球体中的数据点。

我试图弄清楚 dww 对“add_surface”的评论是如何工作的,但无法弄清楚......任何人都可以帮忙吗?

if (!require("rgl")) install.packages("rgl")
dt <- cbind(x = rnorm(100), y = rnorm(100), z = rnorm(100))
ellipse <- ellipse3d(cov(dt))
plot3d(dt)
plot3d(ellipse, add = T, color = "red", alpha = 0.5)
Run Code Online (Sandbox Code Playgroud)

dww 的回答是:

if (!require("plotly")) install.packages("plotly")
if (!require("rgl")) install.packages("rgl")
dt <- cbind(x = rnorm(100), y = rnorm(100), z = rnorm(100))
ellipse <- ellipse3d(cov(dt))

p <- plot_ly(mode = 'markers') %>% 
  add_trace(type = 'scatter3d', size = 1, 
  x = ellipse$vb[1,], y …
Run Code Online (Sandbox Code Playgroud)

r ellipse plotly r-plotly

5
推荐指数
1
解决办法
3148
查看次数

如何使plotly与shiny和gridExtra一起工作?

我正在使用 R闪亮,想在 gridExtra 的帮助下并排放置几个 ggplotly 图。

一张图(没有 gridExtra)效果很好:

library(shiny)
library(plotly)

u <- fluidPage(plotlyOutput(outputId = "myplots"))

s <- function(input, output) {
  pt1 <- reactive({
    ggplotly(qplot(42))
  })

  output$myplots <- renderPlotly({
    pt1()
  })
}

shinyApp(u, s)
Run Code Online (Sandbox Code Playgroud)

现在,当我尝试通过 gridExtra 添加另一幅图时,它拒绝工作:

library(shiny)
library(plotly)
library(gridExtra)

u <- fluidPage(plotlyOutput(
  outputId = "myplots"
))

s <- function(input, output){
  pt1 <- reactive({
    ggplotly(qplot(42))
  })

  pt2 <- reactive({
    ggplotly(qplot(57))
  })

  output$myplots <- renderPlotly({
    grid.arrange(pt1(), pt2(),
                 widths = c(1, 1),
                 ncol = 2)
  })
}

shinyApp(u, s)
Run Code Online (Sandbox Code Playgroud)

给我

gList 中的错误:“gList”中仅允许“grobs”

r gridextra shiny plotly r-plotly

5
推荐指数
1
解决办法
1567
查看次数

如何关闭 Plotly 中显示所有数据的工具提示?

我正在制作一个闪亮的仪表板应用程序。仪表板中的选项卡之一用于我的 Plotly 绘图。我能够很好地显示绘图,但是每当我将鼠标光标放在绘图上超过一秒时,就会出现一个巨大的工具提示,其长度与显示器一样长,显示的数据与我的数据一样多。能适应。这不是 Plotly 内置悬停文本的一部分,这实际上很有用。这就像当您将鼠标悬停在网络上的某些内容上时显示的工具提示。

这是工具提示的一小部分。

显然这是不可接受的。特别是因为这个巨大的工具提示需要一秒钟或更长时间才能加载,所以它会让一切陷入困境。我该如何关闭此功能?这很烦人而且一点用处也没有。我认为解决方案与 JS 或 HTML 相关,但我不确定。任何帮助将不胜感激。提前致谢。

编辑:这是情节调用。我使用 ggplotly 是因为我比plotly更熟悉使用 ggplot 自定义绘图。

library(plotly)     

plot <- ggplot(mydata) + geom_ribbon(aes(ymin = obsAcc25, ymax = obsAcc97, x = x), fill = "cadetblue3", alpha = 0.8) 
    + geom_ribbon(aes(ymin = delAcc25, ymax = delAcc97, x = x), fill = "palegreen3", alpha = 0.8) 
    + geom_ribbon(aes(ymin = actAcc25, ymax = actAcc97, x = x), fill = "dodgerblue4", alpha = 0.8) 
    + theme(panel.grid.major = element_line(color = "grey58"), panel.grid.minor = element_line(color = "grey75")) …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 shiny plotly r-plotly

5
推荐指数
1
解决办法
4271
查看次数

如何在稀疏点之间插入数据以在R&plot中绘制轮廓图

我想根据第一张图中以下彩色点的浓度数据在xy平面上创建等高线图.我在每个高度都没有角点,所以我需要将浓度外推到xy平面的边缘(xlim = c(0,335),ylim = c(0,426)).

在此输入图像描述 点的html文件可以在这里找到:https://leeds365-my.sharepoint.com/:u:/ r/personal /cenmk_leeds_ac_uk/Files/Files/HECOIRA /Chamber%20CO2%20Experiments/Sensors.html?csf = 1&E = HiX8fF

dput(df)
structure(list(Sensor = structure(c(11L, 12L, 13L, 14L, 15L, 
16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 
29L, 1L, 3L, 4L, 5L, 6L, 8L, 30L, 31L, 32L, 33L, 34L, 35L), .Label = c("N1", 
"N2", "N3", "N4", "N5", "N6", "N7", "N8", "N9", "Control", "A1", 
"A10", "A11", "A12", "A13", "A14", "A15", "A16", "A17", "A18", 
"A19", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9", …
Run Code Online (Sandbox Code Playgroud)

r contour extrapolation plotly r-plotly

5
推荐指数
2
解决办法
523
查看次数

具有变化颜色和文本注释的动画绘图仪表图

我有一个我想要动画的仪表图(按照本教程),图的颜色根据当前值而变化。我还想要一个注释*,它显示仪表的当前值(我不希望在扇区中显示标准值)。

为了记录,我正在尝试使用plotly而不是c3::c3_gauge因为我希望最终将它plotly::subplot()与其他同时动画的情节一起嵌入。

我目前有以下几点:

library(plotly)
library(RColorBrewer)

riskToHex <- function(x) {
  x <- colorRamp(rev(brewer.pal(11, "RdYlBu")))(x / 100)
  rgb <- paste(x[,1], x[,2], x[,3], sep = ",")
  paste0("rgb(", rgb, ")")
}

dd <- data.frame(values = c(90, 60, 20))

dd <- dd %>%
  mutate(colors = riskToHex(dd$values),
         frame = seq.int(nrow(dd)))
dd <- merge(dd, data.frame(values = 200 - dd$values,
                           colors = "white",
                           frame = dd$frame),
            all = TRUE) %>%
  arrange(frame)

plot_ly() %>%
  add_pie(values = dd$values,
          frame = dd$frame,
          rotation …
Run Code Online (Sandbox Code Playgroud)

animation r pie-chart plotly r-plotly

5
推荐指数
0
解决办法
721
查看次数

R Plotly:aspectmode='cube' 在 3D 散点图中不使轴相等

我正在制作主成分的 3D 散点图(附图片)。尽管我使用的是aspectmode='cube',但轴的大小不相等。

在此处输入图片说明

我创建了一个 MRE 来测试,在那个测试中,轴是相等的。所以,我很困惑。

axx <- list(
  gridcolor='rgb(255, 255, 255)',
  zerolinecolor='rgb(255, 255, 255)',
  showbackground=TRUE,
  backgroundcolor='rgb(230, 230,230)'
)

df = data.frame(
  X=rnorm(100, mean=-5, sd=2),
  Y=rnorm(100, mean=5, sd=5),
  Z=rnorm(100, mean=20, sd=10),
  color=sample(c('R','G'), 100, replace = T)
)

plot_ly(
  data=df, 
  x = ~X, 
  y = ~Y, 
  z = ~Z, 
  color=~color
  ) %>%
  add_markers(size=3) %>%
  # layout(autosize = F, width = 1000, height = 1000)
  layout(
    # autosize=F,
    # width=700,
    # height=700,
    aspectmode='cube',
    title = 'MiSeq-239 Principal Components',
    scene = …
Run Code Online (Sandbox Code Playgroud)

3d r multiple-axes plotly r-plotly

5
推荐指数
1
解决办法
434
查看次数

ggplotly/plotly 中的长 facet_wrap 标签与 facet 的 strip.background 重叠

我有一个像下面这样的图,我需要在其中显示一个图标题和一些长的方面标签。在ggplot2,它看起来很好。

代表:

library(ggplot2)
library(stringr)
library(plotly)

iris$Species2 <- paste(iris$Species, "... some text to make the label really long and hard to put on a facet label")
iris$Species2 <- str_wrap(iris$Species2, 20)

g <- ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) +
  geom_point() +
  labs(title = "This title isn't helping anyone") + 
  facet_wrap(~Species2)

g
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

但是,转换为动态图并没有按预期工作......刻面标签被切断并进入标题:

gp <- ggplotly(g)
gp
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

之前有一个关于 this 的 SO question,但看起来 OP 没有尝试答案 - 没有人发现建议的答案没有按预期工作。

plotly当涉及到方面时,我对奇怪的行为并不陌生- 请参阅github 上的对话,但我不太了解plotly修改对象以强制它具有更长的 strip.background。

希望有人可以帮助我修改对象gp …

r ggplot2 facet-wrap ggplotly r-plotly

5
推荐指数
1
解决办法
1071
查看次数

使用按时间范围过滤的共享数据创建交互式条形图

我想创建一个交互式条形图,让用户可以根据一系列值过滤观察结果,然后动态呈现所选时间段内每个类的计数。由于过滤后的数据需要可用于许多这样的图表,我认为串扰plotly/ggplot的组合可能会证明是有价值的。

我在下面附加了一个 reprex,它使用共享数据和来自串扰的过滤功能来允许动态过滤部分。当我编织文档时,只要选择了全部范围的值(默认值),条形图就会很好地呈现。

满的

但是,绘图区域对于任何其他区域都为空,即。用户调整范围。

部分的

我到底错过了什么?我认为ggplotly()无法处理的完整共享数据集和过滤共享数据集之间一定存在差异。也许我可以遵循另一种方法来实现我的目标?

这是我的 .Rmd 文件的内容:

---
title: mpg class counts filtered by time period
output: html_document
---

```{r echo = FALSE, message = FALSE, warning = FALSE}
library(crosstalk)
library(plotly)

# Wrap data frame in SharedData
sd = SharedData$new(mpg)

# Create a filter input
filter_slider("Year", "Year", sd, column = ~ year, step = 1, width = 250)

# Render graph
bscols(
  ggplotly(
    ggplot(aes(x = class), data = sd) + 
      geom_bar() …
Run Code Online (Sandbox Code Playgroud)

visualization r ggplotly r-plotly crosstalk

5
推荐指数
1
解决办法
889
查看次数