作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图在每个图上绘制多个带有形状的子图。从下面的代码中,如果我显示一个图,我会得到以下图:
当我在子图中放置这个图的 4 个副本时,我得到以下信息:
正如您所看到的,应该在每个子图中绘制一条的所有 4 条线都已绘制在左上角子图中的原始位置。有什么想法可以解决这个问题吗?
** 编辑 - 使用“纸”
如果我在边缘形状的声明中为外部参照和 yref 使用“纸”,则形状无法正确缩放。也许我在这里在错误的上下文中使用了“纸”?我在下面附上了一张图片
library(plotly)
library(igraph)
tree <- make_tree(127,2)
tree_layout <- layout_as_tree(tree)
tree_layout_df <- as.data.frame(tree_layout)
Xn <- tree_layout_df[,1]
Yn <- tree_layout_df[,2]
edge_shapes = list(
type="line",
line=list(color="#030303",width=5),
opacity=0.3,
x0 = 0, x1=0,
x1 = 5,y1 = 5
)
reg_tree_plot <- plot_ly() %>%
add_trace(x=~Xn[0:63], y=~Yn[0:63], type='scatter', width=700, height=500)
tree_layout <- layout(reg_tree_plot, shapes=edge_shapes)
x <- tree_layout
y <- tree_layout
z <- tree_layout
sub <- subplot(tree_layout,y,z,x,
nrows=2,
margin=0.05,
shareX=FALSE,
shareY=FALSE)
最佳答案
我认为这很明显是 subplot
中的一个错误。在 plotly 中,可以补偿,但它很丑陋,需要维护。如果将其发布到 plotly 站点并查看布局中的数据,则可以看到这一点。注意适当的坐标系似乎是:
x0
在您创建 edge_shape
时两次. library(plotly)
library(igraph)
tree <- make_tree(127,2)
tree_layout <- layout_as_tree(tree)
tree_layout_df <- as.data.frame(tree_layout)
Xn <- tree_layout_df[,1]
Yn <- tree_layout_df[,2]
get_edgeshape <- function(xref,yref,xfak=1,yfak=1){
edge_shapes = list(
type="rect",
line=list(color="#030303",width=5),
opacity=0.3,
x0 = 0*xfak, x1 = 5*xfak,
y0 = 0*yfak, y1 = 5*yfak,
xref=xref,
yref=yref
)
}
reg_tree_plot <- plot_ly() %>%
add_trace(x=~Xn[0:63], y=~Yn[0:63], type='scatter', width=700, height=500)
ycor1 <- 2
ycor2 <- 2*1.125
tree_layout <- layout(reg_tree_plot, shapes=get_edgeshape("x1","y1",yfak=ycor1))
x <- layout(reg_tree_plot, shapes=get_edgeshape("x2","y2",yfak=ycor2))
y <- layout(reg_tree_plot, shapes=get_edgeshape("x3","y3",yfak=ycor1))
z <- layout(reg_tree_plot, shapes=get_edgeshape("x4","y4",yfak=ycor2))
sub <- subplot(tree_layout,y,z,x,
nrows=2,
margin=0.05,
shareX=F,
shareY=F)
sub
devtools::install_github("ropensci/plotly")
这是我的
sessionInfo()
:
R version 3.4.0 (2017-04-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] igraph_1.0.1 plotly_4.7.0 ggplot2_2.2.1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.10 magrittr_1.5 devtools_1.12.0 munsell_0.4.3 xtable_1.8-2 viridisLite_0.2.0 colorspace_1.3-2
[8] R6_2.2.0 rlang_0.1.1 httr_1.2.1 plyr_1.8.4 dplyr_0.5.0 tools_3.4.0 grid_3.4.0
[15] gtable_0.2.0 DBI_0.6-1 git2r_0.18.0 withr_1.0.2 crosstalk_1.0.0 htmltools_0.3.6 yaml_2.1.14
[22] lazyeval_0.2.0 digest_0.6.12 assertthat_0.2.0 tibble_1.3.1 shiny_1.0.3 tidyr_0.6.3 purrr_0.2.2.2
[29] htmlwidgets_0.8 curl_2.5 mime_0.5 memoise_1.1.0 compiler_3.4.0 scales_0.4.1 jsonlite_1.4
[36] httpuv_1.3.3
关于r - Plotly - 使用子图塑造位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44077754/
你好 Stackoverflow, 我现在正在编写 API 相当长的一段时间,现在它可以与这些更大的 API 之一一起使用。开始想知道如何塑造这个 API,因为我多次在更大的平台上看到一个大实体(例如
我想问一下如何在android Material Design中创建改变形状的动画。这是我从 Android Material Design 指南中获得的视频。 Material can change
我正在尝试找出适合我想要拟合的模型的正确语法。这是一个时间序列预测问题,我想在将时间序列输入 LSTM 之前使用一些密集层来改进时间序列的表示。 这是我正在使用的虚拟系列: import pandas
我是一名优秀的程序员,十分优秀!