2
votes

I have a data frame (data) that looks like this:

Condition1   Condition2   Significant?
2.4           5.3            no
9.3           15.9           no
12.1          121.1          yes
0.2           151.3          yes

I am reading in the data.frame and plotting a scatter-plot as follows using qplot:

data<-read.table("input.txt",header=TRUE, row.names=1)

con<-data[,1]
con<-data[,2]
sig<-data[,3]

qplot(con, exp, data = data) + 
geom_point(aes(color=sig), size=I(0.6))

I'm trying to:

a) Colour the points by significance: 'yes' = red, 'no' = black

b) Size the points according to significance: 'yes' = size=I(0.8), 'no' = size=I(0.5)

I can produce a default colour scheme using the above code, but I can't work out how to customise the colours and sizes for the different groups - I imagine it's fairly trivial to do if you know your way around R, but I don't!

1
Why did the user who just posted an answer delete it? I was going to accept it! - fugu
Sorry , i didnt think it was different enough from @Jazzurros, which was posted first. Only difference really is mapping size to a factor rather than a numeric. - user20650
@user20650 - The main difference is that your answer doesn't assume that the values in my example are real (which they clearly aren't), and is therefore more portable - fugu

1 Answers

4
votes

You can use scale_size_manual and scale_colour_manual to set colours and size, both of which you should add to the aesthetics

dat <- read.table(text="Condition1   Condition2   Significant
2.4           5.3            no
9.3           15.9           no
12.1          121.1          yes
0.2           151.3          yes", header=T)

library(ggplot2)

ggplot(dat, aes(Condition1, Condition2, colour=Significant, size=Significant)) +
  geom_point() +
  scale_size_manual(values=c(0.5, 0.8)*10) +
  scale_colour_manual(values=c('no'="black", 'yes'="red"))

enter image description here