本文介绍了用ggplot绘制多个geom_point组的轮廓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我当然有以下代码来绘制: p> 我试图做的是让每个组的大纲遵循每个组中的所有要点 - 而不是像目前那样跳过其中的一些。另外,我希望每个大纲都有一个半透明的填充。谢谢你的帮助。 图书馆(ggplot2)图书馆(重塑)图书馆(汽车) G1< - 1:10 G2< - 11:20 G3< - 21:30 G4< - 31:35 G5< - 36:41 sdata< - read.csv(http://dl.dropbox.com/u/58164604/sdata.csv,stringsAsFactors = FALSE) pdata< - (data)(unique(pdata $ Var)) VarFinalMin< -c() (g in 1:max(VarArea)) { VarNum VarN < - g VarMin VarMinN VarFinalMin } VFinalMin colnames(VFinalMin)< -c(Variable,Value) VarFinalMax< -c ) for(g in 1:max(VarArea)) { VarNum VarN VarMax VarMaxN VarFinalM (VarFinalMax,VarMaxN)} VFinalMax colnames(VFinalMax)< -c(Variable,Value) VFinal VFinal $ Group ggplot(VFinal,aes(Variable,Value,color = Group))+ geom_point() find_hull 船体 ggplot(VFinal,aes(Variable,Value,color = Group))+ geom_point )+ geom_polygon(data = hulls,fill = NA) 解决方案如果您分别对图形的底部和顶部进行升序和降序排序,您可以在原始的 data.frame 上使用 geom_polygon $ c $>并跳过所有的凸包: VLarge 25000) ,] VLarge VSmall VSmall VFinal ggplot(VFinal,aes(Variable,Value,color = Group ))+ geom_point( )+ geom_polygon(aes(fill = Group),alpha = 0.3) I currrently have the code included below to draw this:What I am trying to do is get the outline for each of the groups to follow all of the points in each group - rather than skip some of them as it currently does. In addition I would want each outline to have a semi-transparent fill. Thanks for any help. library(ggplot2)library(reshape)library(car)G1 <- 1:10G2 <- 11:20G3 <- 21:30G4 <- 31:35G5 <- 36:41sdata <- read.csv("http://dl.dropbox.com/u/58164604/sdata.csv", stringsAsFactors = FALSE)pdata<-melt(sdata, id.vars="Var")VarArea <- data.frame(unique(pdata$Var))VarFinalMin <-c()for (g in 1:max(VarArea)){VarNum<-pdata[which(pdata$Var==g),1:c(ncol(pdata))]VarN <- gVarMin <- min(VarNum$value)VarMinN <- cbind(VarN, VarMin)VarFinalMin <- rbind(VarFinalMin,VarMinN)}VFinalMin <- data.frame(VarFinalMin)colnames(VFinalMin)<-c("Variable", "Value")VarFinalMax <-c()for (g in 1:max(VarArea)){VarNum<-pdata[which(pdata$Var==g),1:c(ncol(pdata))]VarN <- gVarMax <- max(VarNum$value)VarMaxN <- cbind(VarN, VarMax)VarFinalMax <- rbind(VarFinalMax,VarMaxN)}VFinalMax <- data.frame(VarFinalMax)colnames(VFinalMax)<-c("Variable", "Value")VFinal<-rbind(VFinalMin, VFinalMax)VFinal$Group <- recode(VFinal$Variable, "G1 = 'A'; G2 = 'B'; G3 = 'C'; G4 = 'D'; G5 = 'E'")ggplot(VFinal, aes(Variable, Value, colour = Group)) + geom_point()find_hull <- function(VFinal) VFinal[chull(VFinal$Variable, VFinal$Value), ]hulls <- ddply(VFinal, "Group", find_hull)ggplot(VFinal, aes(Variable, Value, colour = Group)) + geom_point() + geom_polygon(data = hulls, fill = NA) 解决方案 If you reorder the bottoms and tops of your shapes respectively ascending and descending, you can just use geom_polygon on your original data.frame and skip all the convex hull stuff:VLarge <- VFinal[which(VFinal$Value > 25000),]VLarge <- VLarge[order(-VLarge$Variable, VLarge$Group),]VSmall <- VFinal[which(VFinal$Value <= 25000),]VSmall <- VSmall[order(VSmall$Variable, VSmall$Group),]VFinal <- rbind(VSmall, VLarge)ggplot(VFinal, aes(Variable, Value, colour = Group)) + geom_point() + geom_polygon(aes(fill = Group), alpha = 0.3) 这篇关于用ggplot绘制多个geom_point组的轮廓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-05 20:20