下图与我要找的很接近,但是我想知道以下是否可行:
require(dplyr); require(plotly); require(RColorBrewer); require(stringr)
# Summarise flow data
dat <- data.frame(customer = c(1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 4, 5),
holiday_loc = c("SA", "SA", "AB", "SA", "SA", "SA", "SA", "AB", "AB", "SA", "SA", "SA")) %>%
group_by(customer) %>%
mutate(holiday_num = seq_along(customer),
source=paste0(holiday_loc, '_', holiday_num),
target = lead(source),
last_hol …Run Code Online (Sandbox Code Playgroud) 我想覆盖在顶部的线的Plotly等高线图,类似于覆盖在基质的图像上的线,其中所述强度表示位置z内R3:
# Generate an arbitrary matrix
m <- matrix(sin(1:6^2) * 1:6, nrow = 6)
# Define a path
path <- data.frame(x = c(0:7), y = c(0, 1, 2, 2, 3, 3, 4, 6))
image(x = 1:6, y = 1:6, z = m, col = gray.colors(20), xlab = "x", ylab = "y")
lines(path$x, path$y)
Run Code Online (Sandbox Code Playgroud)
其中呈现:
使用 Plotly,我尝试过
library(plotly)
plot_ly(x = 1:6, y = 1:6, z = t(m), type = "contour") %>%
add_lines(x = path$x, y = path$y) …Run Code Online (Sandbox Code Playgroud) 我正在构建一个应用程序,允许用户使用 selectInput 在绘图图上动态添加和删除跟踪。
我试图从 plotly 包中使用 plotlyProxy () 和 plotlyProxyInvoke () ,但无济于事。
以下是我的基本代码:
library(shiny)
library(shinydashboard)
library(plotly)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
sidebarMenu(
menuItem("Search", tabName = "Tabs", icon = icon("object-ungroup"))
)
),
dashboardBody(
tabItem(tabName = "Tabs",
fluidRow(
column(width=3,
box(
title="SELECT ",
solidHeader=TRUE,
collapsible=TRUE,
width=NULL,
selectInput(
inputId="Player",
selected = NULL, multiple = TRUE,
label=" Choose Player",
choices=c("Messi", "Suarez", "Ronaldo" )),
selectInput(
inputId="Delete",
selected = NULL, multiple = TRUE,
label=" Choose Player",
choices=c("Messi", "Suarez", "Ronaldo" )),
submitButton("Select")
)
),
column( width=9,
tabBox(
width="100%", …Run Code Online (Sandbox Code Playgroud) install.packages(\'plotly\')\nRun Code Online (Sandbox Code Playgroud)\n我尝试通过在RStudioplotly中运行上面的代码来安装该包。但是,它失败并返回以下内容。我是新手,无法正确阅读此内容。我应该怎么做才能解决这个问题?
我也尝试先手动安装curl、openssl安装httr,但没有什么区别。另外,如果相关的话,我正在使用Ubuntu 20.04 LTS。
Installing package into \xe2\x80\x98/home/ariel/R/x86_64-pc-linux-gnu-library/4.0\xe2\x80\x99\n(as \xe2\x80\x98lib\xe2\x80\x99 is unspecified)\nalso installing the dependencies \xe2\x80\x98curl\xe2\x80\x99, \xe2\x80\x98openssl\xe2\x80\x99, \xe2\x80\x98httr\xe2\x80\x99\n\ntrying URL \'https://cloud.r-project.org/src/contrib/curl_4.3.tar.gz\'\nContent type \'application/x-gzip\' length 673779 bytes (657 KB)\n==================================================\ndownloaded 657 KB\n\ntrying URL \'https://cloud.r-project.org/src/contrib/openssl_1.4.3.tar.gz\'\nContent type \'application/x-gzip\' length 1207708 bytes (1.2 MB)\n==================================================\ndownloaded 1.2 MB\n\ntrying URL \'https://cloud.r-project.org/src/contrib/httr_1.4.2.tar.gz\'\nContent type \'application/x-gzip\' length 159950 bytes (156 KB)\n==================================================\ndownloaded 156 KB\n\ntrying URL \'https://cloud.r-project.org/src/contrib/plotly_4.9.2.1.tar.gz\'\nContent type \'application/x-gzip\' length 3709741 bytes (3.5 MB)\n==================================================\ndownloaded 3.5 MB\n\n* installing *source* package …Run Code Online (Sandbox Code Playgroud) 考虑以下 reprex 生成的图。请注意,ggplot 具有合理的图例,而在plotly 中,图例大量重复,每次相同类别(“制造商”)出现在每个方面时都会有一个条目。如何使情节图例更好地匹配 ggplot2 的图例?
library(plotly)
library(ggplot2)
p <- mpg %>%
ggplot(aes(year)) +
geom_ribbon(aes(ymin=cty, ymax=hwy, fill = manufacturer), alpha=0.2) +
geom_line(aes(y = hwy, col=manufacturer)) +
facet_wrap(~class)
p
Run Code Online (Sandbox Code Playgroud)
plotly::ggplotly(p)
Run Code Online (Sandbox Code Playgroud)
我想通过 R 绘制具有独立图例的图,同时尊重色阶。
这就是我所拥有的:
library(plotly)
X <- data.frame(xcoord = 1:6,
ycoord = 1:6,
score = 1:6,
gender = c("M", "M", "M", "F", "F", "F"),
age = c("young", "old", "old", "old", "young", "young"))
plot_ly(data = X, x = ~xcoord, y = ~ycoord, split = ~interaction(age, gender),
type = "scatter", mode = "markers",
marker = list(color = ~score,
colorbar = list(len = .5, y = .3)))
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,颜色条混乱,两个类别纠缠在一起。
我需要为age(年轻与年老)和gender(男与女)分别提供图例,可以彼此独立地单击。这将是预期的结果:

编辑 1
这相当于ggplot2:
gg <- ggplot(X, aes(x …Run Code Online (Sandbox Code Playgroud) 我有一个我想要动画的仪表图(按照本教程),图的颜色根据当前值而变化。我还想要一个注释*,它显示仪表的当前值(我不希望在扇区中显示标准值)。
为了记录,我正在尝试使用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) 我正在制作主成分的 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) 我想创建一个交互式条形图,让用户可以根据一系列值过滤观察结果,然后动态呈现所选时间段内每个类的计数。由于过滤后的数据需要可用于许多这样的图表,我认为串扰和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) 我有一个带有简单散点图(例如地图)的 Rmarkdown,我希望用户能够通过输入提供一些任意x坐标y,并将这些坐标绘制在图表上(在下面的示例中以红色显示)。问题是,我没有闪亮的服务器,所以我不能依赖这个选项。是否有一个实现,例如,通过 javascript 或其他东西?
这就是我所拥有的:
---
title: "Untitled"
output: html_document
---
```{r setup, include=FALSE}
library(ggplot2)
library(plotly)
```
```{r fig.height=4, fig.width=4}
X <- data.frame(x = 1:10, y = 1:10)
gg <- ggplot(X, aes(x, y)) + geom_point()
ggplotly(gg)
```
Run Code Online (Sandbox Code Playgroud)
这就是我正在寻找的:
编辑
上面的例子是一个简化。实际上,网格是360x240,坐标只能是整数。
编辑2 @JohanRosa 已经通过完全在plotly.js 上重建绘图提供了一个很好的答案。然而,我的 ggplot 实际上相当复杂,而且我有很多。因此,将它们重建到plotly.js 对我来说是相当复杂的。这就是我正在寻找一种可以直接在我拥有的 ggplot(ly) 上工作的解决方案的原因。
r-plotly ×10
r ×9
plotly ×6
ggplot2 ×3
ggplotly ×3
3d ×1
animation ×1
crosstalk ×1
javascript ×1
package ×1
pie-chart ×1
r-markdown ×1
shiny ×1
ubuntu-20.04 ×1