- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个 ggplot geom_tile 图,我使用 gridExtra 库中的 grid.arrange() 将它们放在一起。这是结果
library(ggplot2)
library(plyr)
p3 <- ggplot2(...)
p4 <- ggplot2(...)
grid.arrange(p3, p4, ncol=2)
gA <- ggplot_gtable(ggplot_build(p3))
gB <- ggplot_gtable(ggplot_build(p4))
maxHeight <- unit.pmax(gA$heights[2:3], gB$heights[2:3])
gA$heights[2:3] <- maxHeight
gB$heights[2:3] <- maxHeight
grid.arrange(gA, gB, ncol=2)
Error in grid.Call.graphics(L_setviewport, pvp, TRUE) :
non-finite location and/or size for viewport
library(ggplot2)
library(plyr)
temp_plot <- structure(list(Sample = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L),
.Label = c("1", "2", "3", "4", "5", "6", "7", "8"), class = "factor"),
Gene = structure(c(1L, 9L, 21L, 22L, 1L, 7L, 8L, 1L, 2L, 17L, 18L, 1L, 3L, 4L, 16L, 5L, 6L, 19L, 20L, 1L, 10L, 11L, 12L, 13L, 2L, 3L, 4L, 5L, 6L, 14L, 15L),
.Label = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22"), class = "factor"),
Effect = c("fusion", "missense", "missense", "missense", "fusion", "missense", "missense", "fusion", "frameshift", "missense", "nonsense", "fusion", "missense", "missense", "missense", "missense", "missense", "missense", "missense", "fusion", "multiple", "missense", "missense", "missense", "frameshift", "nonsense", "missense", "missense", "missense", "missense", "missense"),
ind = c(1L, 2L, 1L, 2L, 1L, 2L, 3L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 6L, 7L)),
.Names = c("Sample", "Gene", "Effect", "ind"),
row.names = c(NA, -31L), class = "data.frame")
tt <- expand.grid(levels(temp_plot$Gene),levels(temp_plot$Sample))
colnames(tt) <- c("Gene", "Sample")
temp_plot2 <- merge(temp_plot,tt, all.y=T)
p3 <- ggplot(temp_plot2, aes(x=Gene, y=Sample)) +
geom_tile(aes(fill=Effect),colour="white",size=1.1) +
coord_equal() + theme_bw() + theme(axis.text.x = element_blank(),
axis.line = element_blank(), axis.title.y = element_blank(), axis.title.x = element_blank(),
axis.ticks.y = element_blank(), axis.ticks.x = element_blank(),
panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.border = element_blank(), panel.background = element_blank(),
legend.position = "none" )
temp_collapse_plot <- ddply(temp_plot, .(Sample), function(df){
df <- df[order(df$Gene),]
df <- unique(df)
data.frame(df,ind=1:nrow(df))
})
p4 <- ggplot(temp_collapse_plot, aes(y=Sample, x=ind)) +
geom_tile(aes(fill=Effect), colour="white", size=1.1) + coord_equal() +
scale_x_discrete(labels=levels(temp_plot$Gene)[order(nchar(levels(temp_plot$Gene)), decreasing=T)]) +
theme_bw() + theme(axis.line = element_blank(),
axis.text.x = element_blank(), axis.text.y = element_blank(),
axis.ticks.x = element_blank(), axis.title.y = element_blank(),
axis.ticks.y = element_blank(), axis.title.x = element_blank(),
panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.border = element_blank(), panel.background = element_blank())
最佳答案
p3b <- ggplot_build(p3)
p4b <- ggplot_build(p4)
g3 = ggplot_gtable(p3b) ; g4 = ggplot_gtable(p4b)
# work out the number of horizontal tiles
n3 <- length(p3b[["panel"]][["ranges"]][[1]][["x.major_source"]])
n4 <- length(p4b[["panel"]][["ranges"]][[1]][["x.major_source"]])
require(gtable)
require(grid)
g <- cbind(g3, g4, size = "first")
#adjust the panel widths in proportion to n4/n3
panels <- g$layout$l[grep("panel", g$layout$name)]
g$widths[panels] <- lapply(c(1,n4/n3), unit, "null")
grid.newpage()
grid.draw(g)
关于R: ggplot2 使两个 geom_tile 图具有相等的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24188986/
我有一个包含 5 列的数据框: N1 mydf$N1 levels(mydf$N1) #[1] "20" "30" "40" "50" "60" "70" "80" "100" "1
自从切换到 ggplot2 2.0.0 后,在 美学< 之外定义瓷砖的 width 和 height 时出现问题。我使用 geom_tile 创建了某种热图,我想在图 block 之间留一点空间,所以
自从切换到 ggplot2 2.0.0 后,在 美学< 之外定义瓷砖的 width 和 height 时出现问题。我使用 geom_tile 创建了某种热图,我想在图 block 之间留一点空间,所以
这个问题在这里已经有了答案: Margin adjustments when using ggplot's geom_tile() (1 个回答) 8年前关闭。 您可以看到一组有水平灰色边缘,而另一组
set.seed(1990) ID ggplot(dataset + , + aes(x=datetime,y= reorder(ID, n),fill=n))+ +
library(tidyverse) ## make data set.seed(3) dat % tbl_df() %>% rownames_to_column('Var1') %>%
使用 geom_tile,我想在每行数据之间放置一条水平线。看起来如果我在美学上使用颜色,它会在水平和垂直方向上放置线条,这不是我想要的。过去,我只是让瓷砖的高度变小,所以它们之间有一些间隔。但是,似
我正在尝试制作一个按 x 轴上的两个离散变量排序的分面 ggplot。问题是我想让垂直相邻的条目都接触。目前,行与行之间存在空间,具体取决于顶部图中与底部图中的因子水平。抱歉,这个可重现的例子有点冗长
我有两个不同的数据框:P1 和 P2。这些数据帧中的每一个都有 3 个不同的列:N1、N2 和一个值 (mean_RMSE)。 N1和N2在15到120之间,对于一条线,N2总是低于N1。 如果我绘制
我试图显示对 2 个调查问题的响应的密度和相关性。每个问题的答案都是因素 1-5,我想制作一个响应组合表的热图。 我的表格是这样的: > table(mydata$v47, mydata$v78)
我有一个数据框,其中包含来自 20 多个国家/地区的 20 多种产品中每种产品的订单数据。我已使用 ggplot2 将其放在突出显示表中使用与此类似的代码: require(ggplot2) requ
我有一个数据框,我想生成一个 geom_tile()从中绘制,但我希望图形的排序不是基于字母顺序而是基于此数据框中的变量。 structure(list(V1 = c("a", "y", "w", "
我有兴趣在 ggplot2 中使用 geom_tile 构建热图,该热图根据某个因素使用不同的渐变高颜色。 下图创建了一个图,其中各个图 block 根据 xy_type 被着色为蓝色或红色,但没有渐
我想创建一个图表来显示每天的工作时间表。我必须处理的数据看起来像这样: dput(head (TiNiSWeek, 3)) structure(list(`04:00` = c(0, 0, 0)
我正在尝试生成 heatmap使用 ggplot 绘图的 geom_tile .我的数据的行数远多于列数。 set.seed(1) df <- data.frame(val=rnorm(100
我用过 geom_tile()用于在同一张图上绘制 3 个变量...... tile_ruined_coop% group_by("bonus","malus","type","coop") %>%
我试过很多次,一个简单的光栅绘图是空的。但是可以绘制子数据框。所以我考虑了 ggplot 中的一些错误?数据框不是很大,大约 10k 行。 df % slice(1:1000) %>% ggp
我堆叠了一个数据框,它显示 group 中每个 id 的 value: df # A tibble: 11 x 3 #> id value group #> #> 1
我需要帮助为 86x86 矩阵分配正确的十六进制颜色代码到 ggplot + geom_tile()。它是一个相关矩阵,我想根据它的值和由 kmeans 聚类生成的类来给它着色。有六种不同的簇/颜色。
假设我有一个像这样的 data.frame: df <- matrix( rnorm(100), nrow = 10) rownames(df) <- LETTERS[1:10] molten <-
我是一名优秀的程序员,十分优秀!