- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我最近更新了 R 和 Rstudio,自然而然地,我编写的大量脚本已损坏。
特别是导致我出现问题的一件事是下面的脚本。以前它用来输出一个热图,就像它出现在我给它制作矩阵的值的 csv 中一样。现在,后来的版本似乎改变了他们对事物的排序方式。它现在按数字升序对列及其标签进行排序,这使它们无序。如何防止它重新排列列,或指定它按照我提供的方式处理它们?
次要的美学问题并不是什么大问题。
这是代码:
library(ggplot2)
library(plotly)
library(RColorBrewer)
# Read in data
library(readr)
adjwallace <- read.csv() # see the link for the actual data http://pastebin.com/bBLs8uLt
rownames(adjwallace_recluster)[17] <- "Species" #Rename STree
names(adjwallace_recluster)[17] <- "Species"
# Preferences for xaxis
font.pref <- list(
size = 20,
family = "Arial, sans-serif",
color = "black"
)
x.axisSettings <- list(
title = "",
zeroline = FALSE,
showline = FALSE,
showticklabels = TRUE,
tickfont = font.pref,
showgrid = TRUE
)
# Preferences for yaxis
y.axisSettings <- list(
title = "",
zeroline = FALSE,
showline = FALSE,
showticklabels = TRUE,
tickfont = font.pref,
showgrid = TRUE
)
margins <- list(
l = 50,
r = 10,
b = 50,
t = 10,
pad = 1
)
# Plot graph as a heatmap
p <-plot_ly(z = ~data.matrix(adjwallace),
colors = "YlOrRd",
name = "Adjusted Wallace Coefficients",
x = names(adjwallace),
y = names(adjwallace),
colorbar = list(title = "Adjusted Wallace <br> Coefficient", titlefont = font.pref),
type = "heatmap") %>%
layout(xaxis=x.axisSettings,
yaxis=y.axisSettings,
plot_bgcolor='rgba(0,0,0,0)',
paper_bgcolor='rgba(0,0,0,0)',
margin = margins
)
p
最佳答案
新旧热图中的值实际上相同;您的标签只是被重新排序。这是当前版本的 plotly 的奇怪行为(我会让其他人决定是否称其为“错误”)。轴标签按字母顺序重新排序。这是一个 MWE,清楚地显示了它:
dat <- matrix(c(1,2,3), nrow = 30, ncol = 30)
dimnames(dat) <- list(rownames(dat, FALSE, "r"),
colnames(dat, FALSE, "c"))
plot_ly(z=dat, x=colnames(dat), y = rownames(dat),
type = "heat map")
adjwallaceX <- melt(t(as.matrix(adjwallace)))
ggplot(data = adjwallaceX, aes(x = Var1, y = Var2)) +
geom_tile(aes(fill = value)) +
coord_equal() +
scale_fill_gradientn(colours = rev(brewer.pal(9,"YlOrRd"))) +
labs(fill='Adjusted Wallace Coefficient') +
theme(axis.title.x=element_blank(),
axis.title.y=element_blank(),
axis.text.x=element_text(angle = 315, hjust = 0))
关于r - 防止 plot_ly 重新排序矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41231318/
我一直在尝试使用 plot_ly与 transforms (最终从下拉菜单中对数据进行子集化)和颜色映射。 以下是基于 mtcars 的可重现示例: transforms没有颜色映射 如果我排除颜色映
假设我想为线条+标记绘图使用自定义颜色。使用 plot_ly() 的 colors 和 color 参数非常简单,但是一旦我想修改标记本身(使用marker argument) 我遇到了困难并且没有在
我一直在尝试更改在 R 中使用 plot_ly 绘制的图形的 x 和 y 轴上标签的大小. 下面是我的代码: q % layout(xaxis = list(size = 15), yaxis
我是 plot_ly 的新手,但这个条形图工作正常: library(plotly) p % layout(xaxis=list(title=""), showlegend=FALSE,
我有一个数据框 df % layout(showlegend = FALSE,hoverlabel = list(bgcolor= 'white')) 我无法更改每个栏的宽度。我需要一个细条,当我
我最近更新了 R 和 Rstudio,自然而然地,我编写的大量脚本已损坏。 特别是导致我出现问题的一件事是下面的脚本。以前它用来输出一个热图,就像它出现在我给它制作矩阵的值的 csv 中一样。现在,后
我想在一个图上绘制图表并绘制填充区域形状和条形图。然而,区域形状覆盖条。我无法更改元素的顺序。可以把酒吧带在前面吗? data % add_trace(x=data$years, y=data$v
使用 ggplot2 和 plotly 制作带有 facet_wrap() 的交互式散点图。 library(ggplot2) library(plotly) g% ggplot(aes(x =
使用 plot_ly(),我可以在工具提示中添加我想要的内容,但我无法摆脱默认值。有没有办法做到这一点? 在下面的示例中,对于第一点,工具提示是“250 company1”。我只想得到“company
我想创建一个函数,根据传递给它的参数创建不同类型的绘图。如果我创建以下数据 library(plotly) #### test data lead <- rep("Fred Smith", 30) l
我使用 plotly 中的 subplot 函数在我的 R-shiny 应用程序中绘制两个图(一个在另一个下)。两个图的图例都很常见,这意味着我只有一列将所有图例组合在一起。 我想在子图中分别在每个图
我有三个变量:x , y ,和z我想绘制一个曲面图。 z% add_surface() 我收到以下错误 Error: `z` must be a numeric matrix z 到底是什么?如果不是
我找到了一个使用 plot_ly 命令向 add_trace 绘图添加线条的示例。如何在不多次使用 add_trace 的情况下添加要绘制的线列表? 我尝试了一个 for 循环来添加跟踪,但这并没有按
我想知道如何使用 plot_ly 为子图提供不同的字幕。请任何提示。在这种情况下,我获得了一个称号 BB。谢谢。 p %layout(showlegend = FALSE, title="AA"),
将水平显着性条(和星)添加到绘图图的 R plot_ly 命令是什么? "How to draw the boxplot with significant level?" 和 "Put stars o
我正在尝试绘制 3D 散点图(前 3 个维度的 PCA 散点图),但我找不到更改 plot_ly 上的颜色条的方法。 代码在下面,这是我得到的,但我希望它从红色(最负值)到绿色(上限值),转折点(淡粉
这是我的数据集的示例: sampleData Member: ', MEMBER), colorscale = colz ) 最佳答案 一个解决方案是在 sample
似乎每当我使用包 plotly 在 R 中创建图形时,轴标题始终覆盖轴标签。我现在有 2 个图表发生这种情况。我应该使用什么代码来增加轴标题和标签之间的空间 plot_ly()和 ggplot() ?
我正在尝试从 data.frames 列表中绘制多个图。我正在使用 Markdown 来呈现数据。在 R-Studio 中,当我单击“>”运行按钮时,我得到了所有的图。 我尝试使用的代码是: ###
我正在创建一个应用程序,其中包含一些变量的区域数据。该应用程序允许您通过 selectInput 选择用户想要可视化的区域。出于比较/信息目的,我希望用户在 plot_ly 中可视化所选区域以及全国平
我是一名优秀的程序员,十分优秀!