前面也给出了一些ggplot2绘制生信分析基本图形的例子pheatmap|暴雨暂歇,“热图”来袭!!!,ggplot2-plotly|让你的火山图“活”过来,ggplot2|扩展包从0开始绘制雷达图,ggplot2| 绘制KEGG气泡图,ggplot2|绘制GO富集柱形图,ggplot2|从0开始绘制PCA图,ggplot2|ggpubr进行“paper”组图合并,本文将
library(reshape2) # for melt df <- melt(outer(1:4, 1:4), varnames = c("X1", "X2")) p1 <- ggplot(df, aes(X1, X2)) + geom_tile(aes(fill = value)) p2 <- p1 + geom_point(aes(size = value)) # Basic form p1 + scale_fill_continuous(guide = "legend")p1 + scale_fi...
前面也给出了一些ggplot2绘制生信分析基本图形的例子pheatmap|暴雨暂歇,“热图”来袭!!!,ggplot2-plotly|让你的火山图“活”过来,ggplot2|扩展包从0开始绘制雷达图,ggplot2| 绘制KEGG气泡图,ggplot2|绘制GO富集柱形图,ggplot2|从0开始绘制PCA图,ggplot2|ggpub...
# Hide the main title and axis titles p + theme( plot.title = element_blank(), axis.title.x = element_blank(), axis.title.y = element_blank()) Infos This analysis has been performed using R software (ver. 3.1.2) and ggplot2 (ver. )Enjoyed...
本文通过具体实例详细展示了如何在ggplot2中调整legend,提升图形美观度与解读性。首先,加载mtcars数据集作为示例,使用ggplot基础构建图形。重点在于设置legend位置,通过theme参数灵活调整其所在区域。通过修改legend的title与font styles,实现视觉上的个性化定制。设置legend的背景色,增加与背景的一致性和对比度...
p <- ggplot(mtcars, aes(x=gear, y=mpg, fill=gear)) + geom_boxplot() p 设置legend position 使用theme() 参数设置legend位置 # 可选参数为“left”,“top”, “right”, “bottom”. p + theme(legend.position="bottom") # 数值向量 c(x,y) 调控位置 ...
library(ggplot2) library(tidyverse) p <- ToothGrowth %>% ggplot(aes(x=dose,y=len,fill=dose))+ geom_boxplot() p 4更改图例位置 使用theme()函数中的legend.postion语句更改图例的位置,选项有4种:“top”, “bottom”, “left”, “right”。
通过以上参数的设置即完成对所绘制图形的legend的细节修改,得到自己所需要的图形。 参考资料:http://www.sthda.com/english/wiki/ggplot2-legend-easy-steps-to-change-the-position-and-the-appearance-of-a-graph-legend-in-r-software
ggplot2绘图时,legend是默认包含的绘图元素,但是当绘图的aes中不具有区分的标记时(如线型、颜色、形状等)是不生产legend的,以散点图为例说明 1、aes中指定颜色 b <- ggplot(field_data) + geom_point(aes(x1, y1,color='red') ) # 指定点的颜色 b <- b + coord_fixed(xlim = c(0, 100), ylim ...
#gear为横坐标,对mpg做箱线图,gear填充颜色p <- ggplot(mtcars, aes(x=gear, y=mpg, fill=gear)) + geom_boxplot()p 设置legend position 使用theme() 参数设置legend位置 # 可选参数为“left”,“top”, “right”, “bottom”.p + theme(legend.position="bottom") ...