本文介绍了按ggplot2中各列的组合来划分图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在做相关性的组合,并且想在ggplot2中绘制每个组合。然而,我希望每个组合都在一个单独的面板上,而不是一个面板上的所有点。 #制作栏目,在我的我正在做每列之间的相关性(即,col1_col2,col1_col3,col2_col3) col1 col2 col3 df< - data.frame(col1 ,col2,col3) g pre> 我知道这不会让我想要的情节,但我真的难以接受如何在ggplot2中做到这一点。为了清楚起见,我想总共创建三个散点图。 任何帮助都是值得赞赏的! 解决方案 $您的数据 col1 col2 #创建data.frame df< - rbind(data.frame(x = col1,y = col2,cor =1-2), data.frame(x = col1,y = col3,cor =1-3) , data.frame(x = col2,y = col3,cor =2-3)) #绘制 ggplot(df,aes(x,y) )+ geom_point()+ facet_wrap(〜cor,scales =free) I am doing combinations of correlations, and would like to plot in ggplot2 each combination. However I want each combination on a separate panel, rather than all the points on one panel.#making up columns, in my real data I'm doing correlations between each column (ie. col1~col2, col1~col3, col2~col3)col1 <- c(1:10)col2 <- c(12:3)col3 <- c(10, 12, 18, 19, 20, 30, 31, 32, 40, 41)df <- data.frame(col1, col2, col3)g <- ggplot(data=df, aes(x=col1, y=col3)) + geom_point()I knew this wouldn't make my desired plot, but I'm really stumped as to how to approach this in ggplot2. Just to be clear, I want to make three scatter plots in total.Any help is appreciated! 解决方案 require(ggplot2)# Your datacol1 <- c(1:10)col2 <- c(12:3)col3 <- c(10, 12, 18, 19, 20, 30, 31, 32, 40, 41)# Creation of data.framedf <- rbind(data.frame(x=col1, y=col2, cor="1-2"), data.frame(x=col1, y=col3, cor="1-3"), data.frame(x=col2, y=col3, cor="2-3"))# Plottingggplot(df, aes(x, y)) + geom_point() + facet_wrap(~cor, scales="free") 这篇关于按ggplot2中各列的组合来划分图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-05 21:05