当使用R plotly软件包版本4.5.6时,我无法弄清楚如何在使用组合多个图时显示轴标签subplot.这是一个没有出现x轴标签的例子.
require(plotly)
a <- data.frame(x1=1:3, y=30:32)
b <- data.frame(x2=11:13, y=31:33)
u <- plot_ly(a)
u <- add_lines(u, x=~x1, y=~y)
v <- plot_ly(b)
v <- add_lines(v, x=~x2, y=~y)
subplot(u, v, shareY=TRUE)
Run Code Online (Sandbox Code Playgroud) 我想绘制一个带有Plotly的3D-Line Plot用于时间序列并填充每一行.我这里有一个示例代码.
library(plotly)
dens <- with(diamonds, tapply(price, INDEX = cut, density))
data <- data.frame(
x = unlist(lapply(dens, "[[", "x")),
y = unlist(lapply(dens, "[[", "y")),
cut = rep(names(dens), each = length(dens[[1]]$x)))
p <- plot_ly(data, x = ~cut, y = ~x, z = ~y, type = 'scatter3d', mode = 'lines', color = ~cut)
p
Run Code Online (Sandbox Code Playgroud)
用这个代码我可以产生这个图
没有填充的3d线图
我已经尝试过surfaceaxis=0,1或2,他们产生错误的填充物.
3D-Plotly错误填充
我想要的是填充x轴和线图之间的区域.
有一个示例3D图与另一个值.
作为示例3D-Plot,在曲线下填充另一个值
有人可以建议一个方法吗?先感谢您.
编辑:必须使用"plotly"包创建
到目前为止,这就是我所拥有的:
f1 <- list(
family = "Arial, sans-serif",
size = 25,
color = "white"
)
f2 <- list(
family = "Old Standard TT, serif",
size = 14,
color = "black"
)
a <- list(
title = "SALES PER SONG",
titlefont = f1,
showgrid = FALSE,
showticklabels = TRUE,
showline=TRUE,
tickangle = 45,
tickfont = f2
)
salesplot <-plot_ly(producersales, type="scatter", x=Producer, y=SalesPerSong, color=SongRange, colors=cols, mode="markers", size=SalesPerSong) %>%
layout(xaxis = a, yaxis = a)
Run Code Online (Sandbox Code Playgroud)
我尝试paper_bgcolor=#00000000, plot_bgcolor=#00000000在x和y轴信息之后添加layout(),但是当我运行命令时,我得到了加号.我不知道该怎么做,所以任何帮助都表示赞赏.谢谢!
我是 r-plotly 新手,试图找出如何处理不在数据上的点击。似乎使用event_data("plotly_click")I 获取数据中点上的事件,但到目前为止还没有弄清楚如何针对不接近数据但仅在绘图的白色部分上的点击执行此操作。
图中的闪亮点击事件可以做到这一点,我只得到点击的 x 和 y。我想要类似的,但是为了情节。
我可以指定点击事件来自绘图上的任何位置,而不仅仅是数据上吗?
编辑:令人惊讶的是,这在情节中还不存在。查看此功能请求
https://github.com/plotly/plotly.js/issues/2696
https://github.com/ropensci/plotly/issues/1194
因此,在添加此功能之前,我想我的问题是有哪些选项可以做到这一点?看起来像是一个基本功能,我希望对 JavaScript/Shiny/Plotly 有更多了解的人能够破解它。
在这个问题中,从R中的Plotly导出PNG文件我询问了如何将Plotly图导出到磁盘.
我使用了该功能plotly_IMAGE,但后来发现该功能使用了Plotly互联网服务器.
问题是,现在Plotly JavaScript是本地的,如何在没有互联网的情况下创建一个png本地文件?
我试过这段代码但没有成功:
library(plotly)
png(filename = "test.png")
plot_ly(x = 1:10)
dev.off()
Run Code Online (Sandbox Code Playgroud)
我们的想法是在没有点击图表上的导出按钮的情况下进行编程.
我一直在使用的时候有一个问题,ggplotly()一个ggplot图:y轴消失.这是一个使用iris数据集的可重现的例子(这个例子非常简单,但无论如何)
data(iris)
g = ggplot(data = iris, aes(x = Petal.Length, y = Petal.Width, fill = Species)) +
geom_bar(stat = "identity", position = "dodge") +
scale_fill_manual(name = "legend", values = c("blue", "red", "green")) +
ylab("Y title") +
ylim(c(0,3)) +
xlab("X title") +
ggtitle("Main title")
g
ggplotly(g)
Run Code Online (Sandbox Code Playgroud)
如您所见,Y轴标题消失了.
好吧,如果ylim删除它可行,但我想指定y限制.
我试着做以下事情:
data(iris)
g = ggplot(data = iris, aes(x = Petal.Length, y = Petal.Width, fill = Species)) +
geom_bar(stat = "identity", position = "dodge") +
scale_fill_manual(name …Run Code Online (Sandbox Code Playgroud) 我现在是Plotly的初学者,有一个我似乎无法解决的问题.我有我的阴谋堆积条形图,但我不知道如何为每个类别着色.我目前正在使用R.
我目前的代码是:
p = plot_ly(x, x = day, y = count, type = "bar", group = status) %>% layout(barmode = "stack", showlegend = T)
Run Code Online (Sandbox Code Playgroud)
我已经尝试使用"color = "参数和标记,但没有正确的颜色我的图形.
更新10/3/2018:这不是R独有的.它之前已被报道,目前被标记为功能请求,在这里:https://github.com/plotly/plotly.js/issues/260
我正在为r中的plotly图形添加散点图点的自定义悬停文本.它似乎是将文本左对齐,居中对齐或右对齐,具体取决于文本框是分别显示在绘图点的右侧,中间还是左侧.无论盒子的位置如何,我都希望文本始终对齐.我已经能够设置字体样式,例如设置颜色和大小,但无法更改文本对齐方式.
这是一个MRE.我删除了传说,所以最右边的点被迫让他们的悬停框出现在点的左边.
plot_ly(iris,
x = ~Sepal.Length,
y = ~Sepal.Width,
type = 'scatter',
mode = 'markers',
hoverinfo = 'text',
hoverlabel = list(font = list(color = 'white')),
text = ~paste0('Some rather long text',
'\nSepal.Length: ', Sepal.Length,
'\nSepal.Width: ', Sepal.Width)) %>%
layout(showlegend = FALSE)
Run Code Online (Sandbox Code Playgroud)
我有三个变量:x,y和z我想产生一个表面图。
z<-runif(50,0,1)
y<-runif(50,1,2)
x<-runif(50,3,6)
plot_ly(x = ~x, y = ~y, z= ~z) %>% add_surface()
Run Code Online (Sandbox Code Playgroud)
我收到以下错误
Error: `z` must be a numeric matrix
z如果不是垂直轴对应的变量,究竟代表什么?我看过 Volcano 示例,其中他们使用矩阵来生成该图,但我仍然不确定 z 矩阵在该示例中代表什么。
我想要的是让某人绘制一个易于理解的 3D 函数,例如z=f(x,y) = x^2 + y^2使用该surface功能,plot_ly以便我了解如何基于三个变量生成绘图。
我正在尝试通过 R 使用 Plotly 制作森伯斯特图。我正在努力处理层次结构所需的数据模型,无论是在概念化它是如何工作的方面,还是看看是否有任何简单的方法来转换常规数据框,用代表不同层次级别的列,转换为所需的格式。
我已经查看了 R 中绘图森伯斯特图表的示例,例如,here,并查看了参考页面,但没有完全获得数据格式的模型。
# Create some fake data - say ownership and land use data with acreage
df <- data.frame(ownership=c(rep("private", 3), rep("public",3),rep("mixed", 3)),
landuse=c(rep(c("residential", "recreation", "commercial"),3)),
acres=c(108,143,102, 300,320,500, 37,58,90))
# Just try some quick pie charts of acreage by landuse and ownership
plot_ly(data=df, labels= ~landuse, values= ~acres, type='pie')
plot_ly(data=df, labels= ~ownership, values= ~acres, type='pie')
# This doesn't render anything... not that I'd expect it to given the data format doesn't seem …Run Code Online (Sandbox Code Playgroud)