use*_*409 5 r bioinformatics heatmap ggplot2
我绘制了这样的热图:
ggplot(test, aes(start1, start2)) +
geom_tile(aes(fill = logFC), colour = "gray", size=0.05) +
scale_fill_gradientn(colours=c("#0000FF","white","#FF0000"), na.value="#DAD7D3")
Run Code Online (Sandbox Code Playgroud)
这将绘制热图的上三角形。我想绘制的是完全相同的三角形,但斜边为x-axis。
我该怎么做呢?
编辑:添加了可重现的示例
library(ggplot2)
# dummy data
df1 <- mtcars[, c("gear","carb", "mpg")]
# normal tile plot
gg1 <- ggplot(df1, aes(gear, carb, fill = mpg)) +
geom_tile() +
xlim(c(1, 10)) +
ylim(c(1, 10)) +
theme_void() +
theme(legend.position = "none")
Run Code Online (Sandbox Code Playgroud)
预期输出(手动旋转):
使用基本图的相关文章image():
可视化和旋转矩阵
可能的解决方案示例代码位于LDheatmap 包中,使用grid.
使用此解决方案会将输出剪裁在底部,因此解决方法是添加额外的绘图边距,然后用于grid::viewport()旋转:
library(ggplot2) #ggplot2_2.2.1
library(grid)
gg1 <- ggplot(df1, aes(gear, carb, fill = mpg)) +
geom_tile() +
xlim(c(1, 10)) +
ylim(c(1, 10)) +
theme_void() +
# add extra margins
theme(legend.position = "none",
plot.margin = unit(c(1, 1, 1, 1), "cm"))
# then rotate
print(gg1, vp = viewport(angle = 45))
Run Code Online (Sandbox Code Playgroud)