在ggplot2中,我们可以通过theme()函数中的legend.key.size参数来调整图例的大小。这个参数接受一个长度值作为参数,表示图例中图例键的大小。 ggplot(mtcars,aes(x=hp,y=mpg,color=factor(cyl)))+geom_point()+labs(title="汽车马力与油耗关系图",x="马力",y="油耗",color="汽缸数量")+theme_minimal()+th...
ggplot(aes(x=dose,y=len,fill=dose))+ geom_boxplot() p 4更改图例位置 使用theme()函数中的legend.postion语句更改图例的位置,选项有4种:“top”, “bottom”, “left”, “right”。 # top p+theme(legend.position = "top") # bottom p+theme(legend.position = "bottom") # left p+theme(leg...
可以使用theme()函数中的legend.title参数来控制图例标题的大小。以下是如何将图例标题的大小设置为12pt的示例: p+theme(legend.title=element_text(size=12)) 1. [和图例区(legend)之外的位置 plot.title text 标题 ...
p <- ggplot(df1, aes(x=a, y=b))+ geom_point(aes(colour = places), size=3) p#指定图例列数library(scales)p + guides(colour = guide_legend(nrow =2)) p##或换行df1$places<-sub("-","- \n ", df1$places) p = ggplot(df1, aes(x=a, y=b))+ geom_point(aes(colour = places...
p <- ggplot(df1, aes(x=a, y=b))+ geom_point(aes(colour = places), size=3) p#指定图例列数library(scales)p + guides(colour = guide_legend(nrow =2)) p##或换行df1$places<-sub("-","- \n ", df1$places) p = ggplot(df1, aes(x=a, y=b))+ geom_point(aes(colour = places...
另外clusterProfiler里面有一个legend过长的情况,是不能简单的使用scale_color_discrete的,如下: 代码语言:javascript 代码运行次数:0 复制 Cloud Studio代码运行 cnetplot(ego,colorEdge=TRUE,circular=TRUE) 这个图直接使用scale_color_discrete进行修改是不会有任何改变的,因为这个图的color映射并不是ggplot2的默认情况...
library(ggplot2)p <- ggplot(df1, aes(x=a, y=b)) + geom_point(aes(colour = places), size=3)p #指定图例列数 library(scales)p + guides(colour = guide_legend(nrow = 2))p ##或换⾏ df1$places<-sub("-", "- \n ", df1$places)p = ggplot(df1, aes(x=a, y=b)) + geom_...
仔细检查会发现字体大小中坐标轴标题和 legend title 是20磅,图片标题是24磅,坐标轴刻度及 legend text 是16磅;主网格线线宽是3磅,而次网格线线宽是1.5磅。这是因为 ggplot2 默认主题的设置函数theme_bw()的预设代码所致。如需更改,修改自定义theme相应rel即可。 function (base_size = 12, base_family = "...