HI lily, for the colouring of individual points you can set the colour aesthetic. The ID is numeric so ggplot applies a colour scale. If we cast ID to a factor we get the appropriate colouring. test_df <- data.frame(ID = 1:20, v1 = rnorm(20), v2 = rnorm(20), v3 rnorm(20)) ggplot(data=test_df, aes(x=v1,y=v2, colour = as.factor(ID))) + geom_point()+ theme_bw()+ xlab('Variable 1')+ ylab('Variable 2') How to choose a number of samples from the dataset you can use the subset function to select by some variable: sub_test_df1 <- subset(test_df, ID < 5) ggplot(data=sub_test_df1, aes(x=v1,y=v2, colour = as.factor(ID))) + geom_point()+ theme_bw()+ xlab('Variable 1')+ ylab('Variable 2') Or sample a number of random rows using samle() if this is your intention. sub_test_df2 <- test_df[sample(x = 1:nrow(test_df), size = 10), ] ggplot(data=sub_test_df2, aes(x=v1,y=v2, colour = as.factor(ID))) + geom_point()+ theme_bw()+ xlab('Variable 1')+ ylab('Variable 2') HTH Ulrik On Fri, 25 Aug 2017 at 21:38 lily li <chocold12 at gmail.com> wrote:> Hi R users, > > I have some sets of variables and put them into one dataframe, like in the > following. How to choose a specific set of pareto front, such as 10 from > the current datasets (which contains more than 100 sets)? And how to show > the 10 points on one figure with different colors? I can put all the points > on one figure though, and have the code below. I drew two ggplots to show > their correlations, but I want v1 and v3 to be as close as 1, v2 to be as > close as 0. Thanks very much. > > DF > > ID v1 v2 v3 > 1 0.8 0.1 0.7 > 2 0.85 0.3 0.6 > 3 0.9 0.21 0.7 > 4 0.95 0.22 0.8 > 5 0.9 0.3 0.7 > 6 0.8 0.4 0.76 > 7 0.9 0.3 0.77 > ... > > fig1 = ggplot(data=DF, aes(x=v1,y=v2))+ geom_point()+ theme_bw()+ > xlab('Variable 1')+ ylab('Variable 2') > print(fig1) > > fig2 = ggplot(data=DF, aes(x=v1,y=v3)+ geom_point()+ theme_bw()+ > xlab('Variable 1')+ ylab('Variable 3') > print(fig2) > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]

Hi Ulrik, Thanks for your suggestion, but it was not what I meant. I tried to use the rPref package but just got a very small sample and felt clueless. On Sat, Aug 26, 2017 at 12:37 AM, Ulrik Stervbo <ulrik.stervbo at gmail.com> wrote:> HI lily, > > for the colouring of individual points you can set the colour aesthetic. > The ID is numeric so ggplot applies a colour scale. If we cast ID to a > factor we get the appropriate colouring. > > test_df <- data.frame(ID = 1:20, v1 = rnorm(20), v2 = rnorm(20), v3 > rnorm(20)) > > ggplot(data=test_df, aes(x=v1,y=v2, colour = as.factor(ID))) + > geom_point()+ theme_bw()+ > xlab('Variable 1')+ ylab('Variable 2') > > How to choose a number of samples from the dataset you can use the subset > function to select by some variable: > sub_test_df1 <- subset(test_df, ID < 5) > > ggplot(data=sub_test_df1, aes(x=v1,y=v2, colour = as.factor(ID))) + > geom_point()+ theme_bw()+ > xlab('Variable 1')+ ylab('Variable 2') > > Or sample a number of random rows using samle() if this is your intention. > sub_test_df2 <- test_df[sample(x = 1:nrow(test_df), size = 10), ] > > ggplot(data=sub_test_df2, aes(x=v1,y=v2, colour = as.factor(ID))) + > geom_point()+ theme_bw()+ > xlab('Variable 1')+ ylab('Variable 2') > > HTH > Ulrik > > On Fri, 25 Aug 2017 at 21:38 lily li <chocold12 at gmail.com> wrote: > >> Hi R users, >> >> I have some sets of variables and put them into one dataframe, like in the >> following. How to choose a specific set of pareto front, such as 10 from >> the current datasets (which contains more than 100 sets)? And how to show >> the 10 points on one figure with different colors? I can put all the >> points >> on one figure though, and have the code below. I drew two ggplots to show >> their correlations, but I want v1 and v3 to be as close as 1, v2 to be as >> close as 0. Thanks very much. >> >> DF >> >> ID v1 v2 v3 >> 1 0.8 0.1 0.7 >> 2 0.85 0.3 0.6 >> 3 0.9 0.21 0.7 >> 4 0.95 0.22 0.8 >> 5 0.9 0.3 0.7 >> 6 0.8 0.4 0.76 >> 7 0.9 0.3 0.77 >> ... >> >> fig1 = ggplot(data=DF, aes(x=v1,y=v2))+ geom_point()+ theme_bw()+ >> xlab('Variable 1')+ ylab('Variable 2') >> print(fig1) >> >> fig2 = ggplot(data=DF, aes(x=v1,y=v3)+ geom_point()+ theme_bw()+ >> xlab('Variable 1')+ ylab('Variable 3') >> print(fig2) >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/ >> posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> >[[alternative HTML version deleted]]