scale_x_discrete(labels=abbreviate) # In this particular case, it has no effect 7、ggplot2图例设置 7.1、默认图例 library(ggplot2) bp <- ggplot(data=PlantGrowth, aes(x=group, y=weight, fill=group)) + geom_boxplot() bp 7.2、三种方法不显示图例 # Remove legend for a particular aesthetic ...
添加饼图图例 由于geom_polygon&geom_scatterpie都会产生图例,无法只选择一个;因此全部设置show.legend = F;最后通过Legend( )重新绘制图例 lgd=Legend(labels=c("B","C","D"),legend_gp=gpar(fill=c("#FED439FF","#709AE1FF","#197EC0FF")),grid_width=unit(7,"mm"),grid_height=unit(7,"mm")...
p <- ggplot(df) + geom_segment(aes(x=1, xend=2, y=`1952`, yend=`1957`, col=class), size=.75, show.legend=F) + geom_vline(xintercept=1, linetype="dashed", size=.1) + geom_vline(xintercept=2, linetype="dashed", size=.1) + scale_color_manual(labels = c("Up", "Do...
bp + theme(legend.position="top") 1. 也可以根据坐标来设置图例的位置, 左下角为 (0,0), 右上角为(1,1) # Position legend in graph, where x,y is 0,0 (bottom left) to 1,1 (top right) bp + theme(legend.position=c(.5, .5)) 1. 2. # Set the "anchoring point" of the lege...
size=8), #设置图例属性 legend.position = "bottom", legend.text = element_text( ...
group_by(tax$Phylum) %>% # 使用tax中的门水平进行分类summarise_all(sum) %>% rename(Phylum...
Another way to change the legend title and labels is to directly modify the data frame. pg <- PlantGrowth # Copy data into new data frame # Rename the column and the values in the factor levels(pg$group)[levels(pg$group)=="ctrl"] <- "Control" levels(pg$group)[levels(pg$group)==...
labels:坐标轴刻度线标签 limits: 坐标轴范围 其中scale_xx函数可以修改坐标轴的如下参数: 坐标轴标题 坐标轴范围 刻度标签位置 手动设置刻度标签 具体演示: 离散坐标轴 #修改标签以及顺序 p+scale_x_discrete(name="Dose (mg)", limits=c("2", "1", "0.5")) #修改刻度标签 p+scale_x_discrete(brea...
p <- ggplot(df) + geom_segment(aes(x=1, xend=2, y=`1952`, yend=`1957`, col=class), size=.75, show.legend=F) + geom_vline(xintercept=1, linetype="dashed", size=.1) + geom_vline(xintercept=2, linetype="dashed", size=.1) + scale_color_manual(labels = c("Up", ...
3)Example 2: Rename Factor Levels to Change Legend Labels of ggplot2 Plot 4)Video & Further Resources Let’s start right away! Exemplifying Data, Add-On Packages & Basic Graphic Consider the exemplifying data below. data<-data.frame(x=1:6,# Create example datay=1,group=as.factor(letter...