Hi all,
Sorry if this is a bit rudimentary, but I'm trying to create a plot similar to one in the r graph gallary (
http://addictedtor.free.fr/graphiques/graphcode.php?graph=152 ). My first stab at it gets most of the way there, but I'd like it if the maximum size of the points would shrink or expand depending on the size of the graphics device. What would be the best way to achieve this?
TIA,
Ian
circle.plot<-function(x){
x<-as.matrix(x)
n.r<-nrow(x)
n.c<-ncol(x)
dat<-as.data.frame(matrix(NA,n.r*n.c,3))
cnt<-1
for(i in 1:n.r)
for(j in 1:n.c){
dat[cnt,1]<-x[i,j]
dat[cnt,2]<-rownames(x)[i]
dat[cnt,3]<-colnames(x)[j]
cnt<-cnt+1
}
dat<-cbind(dat,0)
dat<-cbind(dat,0)
names(dat)<-c("cor","row","col","x.o","y.o")
p<-qplot(x.o,y.o,data=dat,facets=row~col,size=abs(cor),colour=cor)+
scale_size(limits=c(0,1),to=c(0,10))+xlim(c(-1,1))+ylim(c(-1,1))
p<-p+scale_colour_gradient(limits=c(-1,1),low="#B71B1A",high="#3B4FB8")
o <- opts(panel.grid.minor = theme_blank(), panel.grid.major = theme_blank(),
axis.ticks = theme_blank(), axis.text.y = theme_blank(),
axis.text.x = theme_blank(), axis.title.y = theme_blank(),
axis.title.x = theme_blank(), legend.position = "none")
p+o
}
circle.plot(cor(mtcars))
On Mon, Jun 8, 2009 at 1:42 PM, hadley wickham
<h.wi...@gmail.com> wrote:
Hmmm. The definition of alpha is that it applies to fill colour if
the geom has a fill, otherwise it applies to line colour. There's a
bit of a conflict here, because the boxplot is made up of filled and
non-filled geoms. Alpha will only affect the fill in the next
version.
Hadley
PS. Are you preparing for your meetup talk?
On Mon, Jun 8, 2009 at 3:05 PM, Nicholas Lewin-Koh<ni...@hailmail.net> wrote:
> Hi Hadley,
> Yes, I get your example and it makes sense, thanks. The odd thing is it
> is just the whiskers
> that inherit alpha not the boxes, is that intentional?
>
> Nicholas
>
>
> On Mon, 08 Jun 2009 14:37 -0500, "hadley wickham" <h.wi...@gmail.com>
> wrote:
>> On Mon, Jun 8, 2009 at 11:18 AM, Nicholas Lewin-Koh<ni...@hailmail.net>
>> wrote:
>> >
>> > Hi,
>> > So why in the first example I gave are the whiskers affected by
>> > the level of alpha in qplot, but not using ggplot? At least from my
>> > reading of the docs
>> > I would assume that the controls for geom_boxplot should be separate?
>> > whereas something like
>> > p<-qplot(Smoke,BMI,data=NHANES,facets=~Race,geom=c("jitter","boxplot"),alpha=.2)
>> > p
>> > would have the same alpha for both jitter and the boxplot, but the whole
>> > boxplot
>> > not just the whiskers. Is this not a buglet?
>>
>> It's setting vs. mapping again.
>>
>> qplot(Smoke,BMI,data=NHANES,facets=~Race,geom=c("jitter"),alpha=.2)
>>
>> is equivalent to:
>>
>> ggplot(NHANES, aes(Smoke, BMI, alpha = 0.2)) +
>> geom_jitter() +
>> facet_wrap(~ Race)
>>
>> so when you add on the boxplot the alpha is inherited. What you
>> probably want is to _set_ the value of alpha:
>>
>> qplot(Smoke,BMI,data=NHANES,facets=~Race,geom=c("jitter"),alpha=I(.2))
>>
>> which is equivalent to
>>
>> ggplot(NHANES, aes(Smoke, BMI)) +
>> geom_jitter(alpha = 0.2) +
>> facet_wrap(~ Race)
>>
>> p + geom_boxplot(outlier.colour="white",outlier.size=.1,colour="red")
>>
>> Hadley
>>
>> --
>> http://had.co.nz/
>
--
http://had.co.nz/