[R] helper lines in plot. From point to axis.
This is a very basic question. I am just wondering if there is a function where i can choose a vector of points, and them helper lines are drawn. I am asking because lines seams to be a cumbersome way to do this. E.g. x - 1:36 plot(log(x,1.1),xlab=Number of months, ylab=Visits(1000),main=webpage visits) abline(h=log(12,1.1),col=red,lty=2) mtext(round(log(12,1.1)),side=2,at=log(12,1.1),las=2,outer=F, col=red) abline(h=log(24,1.1),col=red,lty=2) mtext(round(log(24,1.1)),side=2,at=log(24,1.1),las=2,outer=F, col=red) abline(h=log(36,1.1),col=red,lty=2) mtext(round(log(36,1.1)),side=2,at=log(36,1.1),las=2,outer=F, col=red) In this example ablines are easy - but not good because the extend beynd the points. What I would like is something like helper.lines(x=c(12,24,36), lty=2, col=red,text=T) If text=True the lines are annotated with the points corresponding x and y value. Is there something that doed this? Hope my explanation makes sense. Sincerely. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
Re: [R] axis scale
2- If this true,how can i change the given scale to (0.01,0.03,0.05,0.07,0.09)? If you want to change the axis tickmarks you can buildt your plot with yaxt=n and then add an axis with what you want, e.g. axis(side=2,at=c(0.01,0.03,0.05,0.07,0.09),cex.axis=1,las=2) Hope this helps. If not pls. include a reproducable example. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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]] __ R-help@r-project.org mailing list 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.
[R] help with replacing factors
Hi, In the example dataset below - how can I cahnge gray20, to blue # data black - rep(c(black,red),10) gray - rep(c(gray10,gray20),10) black_gray - data.frame(black,gray) # none of this desperate things works # replace(black_gray$gray, gray==gray20,red) # if(black_gray$gray==gray20){black_gray$gray-blue} # for (i in black_gray$gray)if(black_gray$gray[i]==gray20){black_gray$gray[i] -blue} # black_gray$gray==gray14 - blue # black_gray$gray[gray==gray20] - blue # subset(black_gray,gray==gray20,gray) -rep(blue,10) I have a feeling this is me misunderstanding some very basic stuf about the R engine... So any help will be much appreciated. Thanks in advance Andreas [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
Re: [R] help with replacing factors
Hi Mike and Gabor - thx for the help. It seams I have made a mistake in my original question. While Mike's solutions worked on the example data I provided, I now see my actual data is is(df100_lang$gray) [1] character vector data.frameRowLabels and the solution doesn't work. I am sorry for posting the wrong data. If you'd still like to help this is the original data: Thanks for the help (and patience!) df100_lang$gray - structure(c(gray0, gray3, gray7, gray10, gray14, gray17, gray21, gray24, gray28, gray31, gray35, gray38, gray42, gray45, gray48, gray52, gray55, gray59, gray62, gray66, gray69, gray73, gray76, gray80, gray83, gray87, gray90, gray0, gray3, gray7, gray10, gray14, gray17, gray21, gray24, gray28, gray31, gray35, gray38, gray42, gray45, gray48, gray52, gray55, gray59, gray62, gray66, gray69, gray73, gray76, gray80, gray83, gray87, gray90, gray0, gray3, gray7, gray10, gray14, gray17, gray21, gray24, gray28, gray31, gray35, gray38, gray42, gray45, gray48, gray52, gray55, gray59, gray62, gray66, gray69, gray73, gray76, gray80, gray83, gray87, gray90, gray0, gray3, gray7, gray10, gray14, gray17, gray21, gray24, gray28, gray31, gray35, gray38, gray42, gray45, gray48, gray52, gray55, gray59, gray62, gray66, gray69, gray73, gray76, gray80, gray83, gray87, gray90, gray0, gray3, gray7, gray10, gray14, gray17, gray21, gray24, gray28, gray31, gray35, gray38, gray42, gray45, gray48, gray52, gray55, gray59, gray62, gray66, gray69, gray73, gray76, gray80, gray83, gray87, gray90, gray0, gray3, gray7, gray10, gray14, gray17, gray21, gray24, gray28, gray31, gray35, gray38, gray42, gray45, gray48, gray52, gray55, gray59, gray62, gray66, gray69, gray73, gray76, gray80, gray83, gray87, gray90, gray0, gray3, gray7, gray10, gray14, gray17, gray21, gray24, gray28, gray31, gray35, gray38, gray42, gray45, gray48, gray52, gray55, gray59, gray62, gray66, gray69, gray73, gray76, gray80, gray83, gray87, gray90, gray0, gray3, gray7, gray10, gray14, gray17, gray21, gray24, gray28, gray31, gray35, gray38, gray42, gray45, gray48, gray52, gray55, gray59, gray62, gray66, gray69, gray73, gray76, gray80, gray83, gray87, gray90, gray0, gray3, gray7, gray10, gray14, gray17, gray21, gray24, gray28, gray31, gray35, gray38, gray42, gray45, gray48, gray52, gray55, gray59, gray62, gray66, gray69, gray73, gray76, gray80, gray83, gray87, gray90, gray0, gray3, gray7, gray10, gray14, gray17, gray21, gray24, gray28, gray31, gray35, gray38, gray42, gray45, gray48, gray52, gray55, gray59, gray62, gray66, gray69, gray73, gray76, gray80, gray83, gray87, gray90, gray0, gray3, gray7, gray10, gray14, gray17, gray21, gray24, gray28, gray31, gray35, gray38, gray42, gray45, gray48, gray52, gray55, gray59, gray62, gray66, gray69, gray73, gray76, gray80, gray83, gray87, gray90), .Label = character(0)) On Sun, May 24, 2009 at 2:12 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: Try storing them as character strings rather than factors: black_gray - data.frame(black, gray, stringsAsFactors = FALSE) Try this to view what you've got: str(black_gray) On Sun, May 24, 2009 at 7:15 AM, Andreas Christoffersen achristoffer...@gmail.com wrote: Hi, In the example dataset below - how can I cahnge gray20, to blue # data black - rep(c(black,red),10) gray - rep(c(gray10,gray20),10) black_gray - data.frame(black,gray) # none of this desperate things works # replace(black_gray$gray, gray==gray20,red) # if(black_gray$gray==gray20){black_gray$gray-blue} # for (i in black_gray$gray)if(black_gray$gray[i]==gray20){black_gray$gray[i] -blue} # black_gray$gray==gray14 - blue # black_gray$gray[gray==gray20] - blue # subset(black_gray,gray==gray20,gray) -rep(blue,10) I have a feeling this is me misunderstanding some very basic stuf about the R engine... So any help will be much appreciated. Thanks in advance Andreas [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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]] __ R-help@r-project.org mailing list 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.
Re: [R] Read many .csv files into an R session automatically, without specifying filenames
I really dont know hot to use it - but have a look at ?source On Mon, May 11, 2009 at 10:37 PM, Mark Na mtb...@gmail.com wrote: Hi R-helpers, I would like to read into R all the .csv files that are in my working directory, without having to use a read.csv statement for each file. Each .csv would be read into a separate dataframe which would acquire the filename of the .csv. As an example: Mark-read.csv(Mark.csv) ...but the code (or command) would do this automatically for every .csv in the working directory without my specifying each file. I'd appreciate any help or ideas you might have. Thanks! Mark Na __ R-help@r-project.org mailing list 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]] __ R-help@r-project.org mailing list 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.
Re: [R] function for nice correlation output with significance symbols
Maybe pairs.panels(df,scale=T) from the psych library - se more here: http://www.personality-project.org/r/html/00.psych-package.html setting scale=T scales the cor coefficient according to their value. I have seen an implementation with added asterix' but couldn't find it right now. On Sun, May 10, 2009 at 10:36 PM, Chuck Cleland cclel...@optonline.net wrote: On 5/10/2009 3:26 PM, Martin Batholdy wrote: hi, I am searching for a nice function which computes correlations out of a data.frame and adds asterix-signs after each correlation when they are significant... ...or a function which just show correlations greater than x in the output. thanks! __ R-help@r-project.org mailing list 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.
Re: [R] Bumps chart in R
On Thu, May 7, 2009 at 2:15 AM, Mike Lawrence mike.lawre...@dal.ca wrote: (cross posting to the ggplot2 group for posterity) Here's how I'd approach it: library(ggplot2) text = letters[1:20] tal1 = rnorm (20,5,2) tal2 = rnorm (20,6,3) dif = tal2-tal1 df0 = data.frame(text,tal1,tal2) df = melt( data = df0 , id.vars = 'text' , variable_name = 'tal' ) df$dif = dif df$col = ifelse(dif0,'red',ifelse(dif0,'blue','black')) df$size = abs(dif) # draw the plot Unfortunately it's not perfect: (1) col isn't being interpreted literally, so instead of truly red blue. (2) the lines ends are square whereas usually they're rounded. (3) attempting to remove the legend via opts(legend.position=none) seems to fail. Thank you with your melted data I was able to come very close to what I want. legen.posistion=none works for me... Annonying that colours don't work like expected... It seams to be a frequent concern. My code: qplot(tal,value,data=df,group=text,geom=line,size=size,colour=col,xlab=Change from time to time, ylab = Points)+ geom_text(aes(label=text),subset(df,tal==tal1),size=3,hjust=2,vjust=0)+ theme_bw()+ opts(legend.position=none)+ opts(title=As time went by) +opts(plot.title=theme_text(vjust=0,size=20)) __ R-help@r-project.org mailing list 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.
Re: [R] Bumps chart in R
Thank you Thierry! That was very helpfull I have added geom_point which makes the lineending look more round. Also - since the chart becomes verye clustered I also added text to the right. like so: ggplot(df, aes(x = tal, y = value, label = text, group = text, size = size, col = Change))+ geom_line()+ geom_text(data = subset(df, tal==tal1),size=3, hjust=1, vjust=0)+ geom_text(data = subset(df, tal==tal2),hjust=-1, size=3)+ geom_point() + scale_x_discrete(Change from time to time) + scale_y_continuous(Points) + theme_bw()+ opts(legend.position=none)+ opts(title=As time went by)+ opts(plot.title=theme_text(vjust=0,size=20))+ scale_colour_manual(values = c(red, black, blue)) Thanks for all your help! On Thu, May 7, 2009 at 1:17 PM, ONKELINX, Thierry thierry.onkel...@inbo.be wrote: Dear Andreas and Mike, You need to use scale_colour_manual() if you want to set the colours yourself. Ggplot2 interpretes the col variable in the dataset as an ordinairy factor. library(ggplot2) df0 - data.frame(text = letters[1:21], tal1 = c(rnorm (20,5,2), 5), tal2 = c(rnorm (20,6,3), 5)) df0$dif - df0$tal2 - df0$tal1 df - melt(data = df0, id.vars = c('text', 'dif'), variable_name = 'tal') df$Change - factor(ifelse(df$dif0,'Up',ifelse(df$dif0,'Down','Stable')), levels = c(Up, Stable, Down)) df$size - abs(df$dif) ggplot(df, aes(x = tal, y = value, label = text, group = text, size = size, col = Change)) + geom_line() + geom_text(data = subset(df, tal==tal1), size=3, hjust=2, vjust=0) + scale_x_discrete(Change from time to time) + scale_y_continuous(Points) + theme_bw()+ opts(legend.position=none)+ opts(title=As time went by\n) +opts(plot.title=theme_text(vjust=0,size=20)) + scale_colour_manual(values = c(red, black, blue)) HTH, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens Andreas Christoffersen Verzonden: donderdag 7 mei 2009 12:22 Aan: Mike Lawrence; r-help@r-project.org; ggpl...@googlegroups.com Onderwerp: Re: [R] Bumps chart in R On Thu, May 7, 2009 at 2:15 AM, Mike Lawrence mike.lawre...@dal.ca wrote: (cross posting to the ggplot2 group for posterity) Here's how I'd approach it: library(ggplot2) text = letters[1:20] tal1 = rnorm (20,5,2) tal2 = rnorm (20,6,3) dif = tal2-tal1 df0 = data.frame(text,tal1,tal2) df = melt( data = df0 , id.vars = 'text' , variable_name = 'tal' ) df$dif = dif df$col = ifelse(dif0,'red',ifelse(dif0,'blue','black')) df$size = abs(dif) # draw the plot Unfortunately it's not perfect: (1) col isn't being interpreted literally, so instead of truly red blue. (2) the lines ends are square whereas usually they're rounded. (3) attempting to remove the legend via opts(legend.position=none) seems to fail. Thank you with your melted data I was able to come very close to what I want. legen.posistion=none works for me... Annonying that colours don't work like expected... It seams to be a frequent concern. My code: qplot(tal,value,data=df,group=text,geom=line,size=size,colour=col,xlab=Change from time to time, ylab = Points)+ geom_text(aes(label=text),subset(df,tal==tal1),size=3,hjust=2,vjust=0)+ theme_bw()+ opts(legend.position=none)+ opts(title=As time went by) +opts(plot.title=theme_text(vjust=0,size=20)) __ R-help@r-project.org mailing list 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. Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo
Re: [R] Bumps chart in R
Okay - first off: Thank you all for you kind help so far. (Especially to hadly for writing ggplot2). I feel that I am beginning to understand the grammar of graphics - but obviously still have a long way to go. Some of the road I need to travel has to do with basic R. Anyway ; instead of wrting a new post - I thought it best to post in the current topic. please correct me if I am wrong. getting to the point: I have expanded upon the original bumps chart (or what ever type of chart it is). I'd like the line width to be proportional to the change between time 1 and time 2. Also: I'd like colous to be red if the change is negative, and black if the change is positive. My solutions produces some problems for me: library(ggplot2) # Loads ggplot2 text - letters[1:20] # letters is proxy for categories tal1 - rnorm (20,5,2) # random numbers for first tal2 - rnorm (20,6,3) # random numbers for second dif - tal2-tal1 # difference between second and first df0 - cbind(tal1,tal2,dif) # do dataframe df - melt(df0) # melt farve - c(2,1,1,2,2,1,2,2,2,2,1,1,1,2,2,1,1,1,2,2) # define colours - black for positive change, red for negative change # these colours I handcode - depending on the random generated - so it will not fit new data. # draw the plot qplot(X2, value,data=df, group=X1,geom=blank)+ geom_line(aes(group=X1),subset(df,X2!=dif),size=scale(abs(subset(df,df$X2==dif)$value),center=F,scale=T)[,1],colour=farve)+ geom_text(aes(label=X1),subset(df,X2==tal2),size=3,hjust=-3,vjust=1)+theme_bw() # My questions: # How to do colours automaticaly # how to remove dif from the X axis? - subset doesn't seem to work? - eg # qplot(subset(df,X2!=dif,X2, drop=T), value,data=df) - returns an error. # Hot to use melt better - so that text becomes the id? id=text doesn't work. thanks in advance On Tue, Apr 28, 2009 at 12:09 AM, Andreas Christoffersen achristoffer...@gmail.com wrote: My legend is removed! - Couldn't find it in your ggplot2 book - but here it is. Brilliant - thank you very much. __ R-help@r-project.org mailing list 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.
Re: [R] Bumps chart in R
thank you kindly - will do :-) Cheers On Mon, Apr 27, 2009 at 1:21 AM, Gabor Grothendieck ggrothendi...@gmail.com wrote: Have a look at plotweb in the bipartite package. On Sun, Apr 26, 2009 at 6:45 PM, Andreas Christoffersen achristoffer...@gmail.com wrote: Hi there, I would like to make a 'bumps chart' like the ones described e.g. here: http://junkcharts.typepad.com/junk_charts/bumps_chart/ Purpose: I'd like to plot the proportion of people in select countries living for less then one USD pr day in 1994 and 2004 respectively. I have already constructed a barplot - but I think a bumps chart would be better # The barplot and data countries - c(U-lande, Afrika syd for sahara, Europa og Centralasien, Lantinamerika og Caribien,Mellemøstenog Nordafrika, Sydasien,ØStasien og stillehaveet, Kina, Brasilien) poor_1990 - c(28.7,46.7,0.5,10.2,2.3,43,29.8,33,14) poor_2004 - c(18.1,41.1,0.9,8.6,1.5,30.8,9.1,9.9,7.5) poor - cbind(poor_1990,poor_2004) rownames(poor) - countries oldpar - par(no.readonly=T) par - par(mar=c(15,5,5,1)) png(poor.png) par - par(mar=c(15,5,5,1)) barplot(t(poor[order(poor[,2]),]),beside=T,col=c(1,2),las=3,ylab=% poor,main=Percent living for 1 USD per day (1993 prices),ylim=c(0,50)) legend(topleft,c(1990,2004),fill=c(1,2),bty=n) par(oldpar) dev.off() I Guess I need to start with an normal plot? Something like the below - but there is a loong way to go... # A meager start - how to finish my bumps chart plot(c(rep(1,9),rep(2,9)),c(fattig_1990,fattig_2004),type=b,ann=F) Thankfull for any help. Cheers. Andreas __ R-help@r-project.org mailing list 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. __ R-help@r-project.org mailing list 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.
Re: [R] Bumps chart in R
In statistics, a bumps chart is more commonly called a parallel coordinates plot. Thank you. However - my understanding of the parallel coordinates plot is that you have factors, not time, on the x axis. Also the 'bump chart' i invision is best suited for only two different x categories. But technically I guess you are right. Cheers. __ R-help@r-project.org mailing list 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.
Re: [R] Bumps chart in R
On Mon, Apr 27, 2009 at 2:23 AM, Mike Lawrence mike.lawre...@dal.ca wrote: Here's a ggplot2 based solution: Wauw - thank you. I'm sure I need to understand gplot better. With qplot I can make something similar - quite easy. With your reformattet data: #here's the data provided by Andreas countries - c(U-lande, Afrika syd for sahara, Europa og Centralasien, Lantinamerika og Caribien,Mellemøstenog Nordafrika,Sydasien,ØStasien og stillehaveet, Kina, Brasilien) poor_1990 - c(28.7,46.7,0.5,10.2,2.3,43,29.8,33,14) poor_2004 - c(18.1,41.1,0.9,8.6,1.5,30.8,9.1,9.9,7.5) #reformat the data data = data.frame(countries,poor_1990,poor_2004) data = melt(data,id=c('countries'),variable_name='year') levels(data$year) = c('1990','2004') #make a new column to make the text justification easier data$hjust = 1-(as.numeric(data$year)-1) library(ggplot2) qplot(year,value, data=data,label=countries, geom=c(line,text), group=countries, col=countries) But I would like to have the text labels show only once - e.g. at 1990 - and also control the size of the text. In my crude qplot, setting size=2 e.g. changes not only the text, but also the lines etc. I guess I have to move from qplot to gplot. __ R-help@r-project.org mailing list 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.
Re: [R] Bumps chart in R
Hi Andreas, Not too hard. Try this: Amazing! - a bump.plot function - so cool. I love it when I simultaneously realize the power of R and my own limitations with R. I must learn how to write my own functions (suggestions for good introduction are very welcome) But: When I run the following bump.plot(poor_1990,poor_2004,c(1990,2004),countries, linecol=1:20, pch=16, main=Bumps plot ,rank=F) 1: It seams the data is somehow sorted/ordered perversely: Now Kina (Danish for China) e.g. has traded places with Afrika syd for sahara (Danish for Africa south of Sahara), etc. 2: When I set e.g. right.labels=NULL - I get a lot of empty space. How could I remove it? p.s. For aesthetics I've change a tiny part of your function to plot(c(rep(1,ny),rep(2,ny)),c(rev(y1),rev(y2)),xlim=c(0,3),xlab=,ylab=, axes=T,xaxt=n,yaxt=s,bty=n,...) Thereby adding an Y axis. - I don't really know whats going on - but I could guess this was were the axis magic happened. Cheers - a very gratefull andreas (especially if someone can help with the misplaces labels mentioned in 1 above) __ R-help@r-project.org mailing list 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.
Re: [R] Bumps chart in R
Or just add the text layer separately: qplot(year, value, data = data, geom = line, group = countries) + geom_text(aes(label = countries), subset = .(year == 1990), hjust = 1, size = 3, lineheight = 1) THX a lot! The subset did not work for me, but this does: subset(data,year == 1990) Andreas __ R-help@r-project.org mailing list 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.
Re: [R] Bumps chart in R
I am sorry - but maybe someone will help me with the final puzzle. How to remove the legend from the qplot? I can google my way to something like sc - scale_fill_continuous() s...@legend - FALSE but qplot(year, value, data = data, xlab=År,ylab=% i ekstrem fattigdom, geom = line, group = Lande,col=Lande) + sc + geom_text(aes(label = Lande), subset(data,year == 1990), hjust = 0.5,vjust=0, size = 3, lineheight = 1) doesnot work. Is there no simple way to just: legend=F ? On Mon, Apr 27, 2009 at 8:53 PM, Andreas Christoffersen achristoffer...@gmail.com wrote: Or just add the text layer separately: qplot(year, value, data = data, geom = line, group = countries) + geom_text(aes(label = countries), subset = .(year == 1990), hjust = 1, size = 3, lineheight = 1) THX a lot! The subset did not work for me, but this does: subset(data,year == 1990) Andreas __ R-help@r-project.org mailing list 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.
Re: [R] Bumps chart in R
Is there no simple way to just: legend=F ? + opts(legend.position = none) Hadley My legend is removed! - Couldn't find it in your ggplot2 book - but here it is. Brilliant - thank you very much. __ R-help@r-project.org mailing list 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.
[R] Bumps chart in R
Hi there, I would like to make a 'bumps chart' like the ones described e.g. here: http://junkcharts.typepad.com/junk_charts/bumps_chart/ Purpose: I'd like to plot the proportion of people in select countries living for less then one USD pr day in 1994 and 2004 respectively. I have already constructed a barplot - but I think a bumps chart would be better # The barplot and data countries - c(U-lande, Afrika syd for sahara, Europa og Centralasien, Lantinamerika og Caribien,Mellemøstenog Nordafrika, Sydasien,ØStasien og stillehaveet, Kina, Brasilien) poor_1990 - c(28.7,46.7,0.5,10.2,2.3,43,29.8,33,14) poor_2004 - c(18.1,41.1,0.9,8.6,1.5,30.8,9.1,9.9,7.5) poor - cbind(poor_1990,poor_2004) rownames(poor) - countries oldpar - par(no.readonly=T) par - par(mar=c(15,5,5,1)) png(poor.png) par - par(mar=c(15,5,5,1)) barplot(t(poor[order(poor[,2]),]),beside=T,col=c(1,2),las=3,ylab=% poor,main=Percent living for 1 USD per day (1993 prices),ylim=c(0,50)) legend(topleft,c(1990,2004),fill=c(1,2),bty=n) par(oldpar) dev.off() I Guess I need to start with an normal plot? Something like the below - but there is a loong way to go... # A meager start - how to finish my bumps chart plot(c(rep(1,9),rep(2,9)),c(fattig_1990,fattig_2004),type=b,ann=F) Thankfull for any help. Cheers. Andreas __ R-help@r-project.org mailing list 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.
[R] ggplot2 - boxplot of variables / columns
Hi, ggplot/qplot is great - it has really helped me do some nice things. However, simple boxplot of different columns/variables is a bit tricky, because of (i think) qplot's generic Y conditional on X input form. Se below. # Some data: a - rnorm(100) b - rnorm(100,1,2) c - rnorm(100,2,0.5) # normal boxplot of a,b,c boxplot(a,b,c) # Looks good library(ggplot2) # loads qqplot2 # Tries do replicate the simple boxplot qplot(a,b,c, geom=boxplot) # Not good # Workaround d - c(a,b,c) e - c(rep(a,100),rep(b,100),rep(c,100)) qplot(e,d,geom=boxplot) # Works - but there must be a simpler way? What is the simple to compare multiple variables like this? thanks in advance __ R-help@r-project.org mailing list 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.
Re: [R] ggplot2 - boxplot of variables / columns
David, you solution qplot(ind, values, data=stack(data.frame(a,b,c)), geom=boxplot) Works a treat - thank you! Thierry, your solution ds - data.frame(a = a, b = b, c = c) library(ggplot2) # loads qqplot2 ggplot(melt(ds), aes(x = variable, y = value)) + geom_boxplot() Also works. I can even combine the two solutions, using stack / melt interchangeably. I am very glad that today I both learned melt/stack and Thierry has made me curious as to the finer ggplots fine tuning wizardry in ggplot vs. the simple qplot. Again - thx. __ R-help@r-project.org mailing list 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.
Re: [R] R and vim (gvim) on ubuntu
I'd recommend to use this script instead. It uses screen to communicate R and vim, it works well. http://www.vim.org/scripts/script.php?script_id=2551 Best, - -Jose - -- Jose Quesada, PhD. Max Planck Institute, Center for Adaptive Behavior and cognition, Berlin http://www.josequesada.name/ Hi Jose, Thanks for that script. It works very well as a substitute/replacement for r-plugin. Only two things: 1) I can't send selection of text? When I try with :VicleSend I get: E481: No range allowed. 2) When I send the whole file to my rSession screen all the text disapears from vim... I can of cause get i back with u- but still. Hope you have a solution, Sincerely [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.