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...
ggplot(hw,aes(x=ageYear, y=heightIn, shape=sex, fill=weightGroup))+ geom_point(size=2.5)+ scale_shape_manual(values = c(21,24))+ scale_fill_manual(values = c(NA,"orange"), guide=guide_legend(override.aes = list(shape=21))) #指定图例键的美学参数的列表 #help(scale_fill_manual)...
p1 <- ggplot(df, aes(X1, X2)) + geom_tile(aes(fill = value)) p1 + scale_fill_continuous(guide = guide_legend()) 我们可以为它设置各种样式,如 # 设置图例标题的位置 p2 <- p1 + guides(fill = guide_legend(title = "LEFT", title.position = "left")) # 使用 element_text 设置图例...
多掌握几个图例Legend,更好地利用R语言绘图。 legend(x, y = NULL, legend, fill = NULL,col =, bty = "o",xjust = 0, yjust = 1, x.intersp = 1, y.intersp =1, adj = c(0, 0.5), text.width = NULL,xpd=TRUE) 1. Legend定位 1. 如果图例绘在制图区外,必须提前保留绘制legend的空间。
图例的四种形式:fill, color, shape, size,使用guides函数时,使用相应参数即可。 AI检测代码解析 df <- data.frame(x=1:20,y=1:20,color=letters[1:20]) p <- ggplot(df,aes(x,y))+geom_point(aes(color=color)) p+guide_legend(title='legend',nrow = 4,ncol = 5) #error ...
ggplot(data = NULL, mapping = aes()) 两个重要参数: data: 用于指定要用到的数据源,必须使数据框类型 mapping:使用aes()函数指定每个变量的角色,除x和y之外的其他参数,例如,size、color、shape等,必须采用name=value的形式。 在ggplot中设置的映射是默认映射关系,其他图层中可以继承该映射关系,或修改映射关系...
ggplot(data=data.frame(x=1:5,y=2,group=c("A","A","A","B","B")), aes(x=x,y=y))+ geom_star(starshape=15,angle=0,size=10, aes(fill=group), show.legend = FALSE)+ theme_bw()+ theme(panel.grid = element_blank()) 代码语言:javascript 代码运行次数:0 复制Cloud Studio 代...
dat<-data.frame(x=LETTERS[1:3],y=1)p<-ggplot(dat,aes(x,y,fill=x,colour=1:3))+geom_bar(stat="identity")+theme(legend.background=element_rect(colour="black"))# These two are the same p+guides(color=guide_colorbar(order=0),fill=guide_legend(order=0))p+guides(color=guide_color...
p <- ggplot(heightweight, aes(x=ageYear, y=heightIn, shape=sex, colour=sex))+geom_point() p 可以在scale_*函数中修改: p + scale_shape_discrete(name = "shape")+ scale_color_discrete(name = "colooorrr") 也可以在legend中修改: ...
ggplot(Salaries,aes(x=yrs.since.phd, y=salary, color=rank,shape=sex)) + geom_point() 图19-9 博士毕业年数和薪水的散点图 学术等级用点的颜色来表示(红色代表助理教授,绿色代表副教授,蓝色代表教授)。 性别用点的形状来表示(圆形代表女性,三角...