tag:blogger.com,1999:blog-7556813435224291579.post3160081447853948352..comments2023-03-23T10:46:08.543+00:00Comments on One R Tip A Day: Barplots of two setsPaolohttp://www.blogger.com/profile/01969817827028660433noreply@blogger.comBlogger16125tag:blogger.com,1999:blog-7556813435224291579.post-32486240850094285462013-11-02T11:37:03.220+00:002013-11-02T11:37:03.220+00:00Thank's so much, your example was very useful ...Thank's so much, your example was very useful to me :)Unknownhttps://www.blogger.com/profile/15186536300457272952noreply@blogger.comtag:blogger.com,1999:blog-7556813435224291579.post-86450722071353548672013-02-05T20:07:39.070+00:002013-02-05T20:07:39.070+00:00Ops, ci siamo sovrapposti! ;-) Sono contento, ma n...Ops, ci siamo sovrapposti! ;-) Sono contento, ma non stupito, che l'effetto auto-maieutico ( come mi piace chiamare quando una persona chiede aiuto e prima di ricevere risposta trova da solo la soluzione al suo problema) abbia funzionato ancora una volta! ;-) Se ritieni che sia possibile pubblicare la tua soluzione (con dati fittizi magari) per aiutare altri che SICURAMENTE si scontreranno col tuo stesso problema non esitare a farlo di seguito! Grazie! Paolohttps://www.blogger.com/profile/01969817827028660433noreply@blogger.comtag:blogger.com,1999:blog-7556813435224291579.post-26639572678707297082013-02-05T19:58:13.900+00:002013-02-05T19:58:13.900+00:00Non sia mai che tu sia costretta a tornare ad Exce...Non sia mai che tu sia costretta a tornare ad Excel!<br /><br />Onestamente non mi è chiaro (è tardi anche per me ;-) ) come tu intenda organizzare i dati per visualizzarli con un barplot.<br />Per questo tipo di barplot con fattori i pacchetti plyr e ggplot2 mi sembrano i più adatti.<br />Per un barplot che raggruppa le barre per un fattore a scelta (mettiamo la colonna D nel tuo caso) qualcosa di simile dovrebbe (spero) indirizzarti verso la retta via:<br /><br />library(ggplot2)<br />ggplot(stem, aes(x=Date,y=Exp_Flux, fill=D)) + geom_bar(position="dodge") <br /><br />e per uno stacked:<br /><br />ggplot(stem, aes(x=Date,y=Exp_Flux, fill=D)) + geom_bar(position="identity")<br /><br />Ovviamente questo non funzionerà "as it is" quindi il riferimento al manuale di ggplot2 è d'obbligo:<br />http://docs.ggplot2.org/0.9.3/geom_bar.html<br /><br />Ci sono diversi esempi che sono certo ti aiuteranno a trovare la soluzione al tuo problema.<br /> <br />Buon Lavoro!Paolohttps://www.blogger.com/profile/01969817827028660433noreply@blogger.comtag:blogger.com,1999:blog-7556813435224291579.post-27162295689136374422013-02-05T19:54:40.168+00:002013-02-05T19:54:40.168+00:00Scusa se ti ho disturbato inutilmente
Sembra incre...Scusa se ti ho disturbato inutilmente<br />Sembra incredibile ma quando senti che stai per affogare, chiedi aiuto e all'improvviso emergi da quel profondo mare di disperazione!<br />Ce l'ho fatta :)<br />Non ci stavo capendo veramente nulla, lavoRaRe tRoppo = lavoRaRe male!<br />ciao ciaoCskenehttps://www.blogger.com/profile/15569292060166258710noreply@blogger.comtag:blogger.com,1999:blog-7556813435224291579.post-4878003073237822702013-02-05T19:07:49.661+00:002013-02-05T19:07:49.661+00:00Ciao Paolo,
sono in preda a una crisi di nervi, ca...Ciao Paolo,<br />sono in preda a una crisi di nervi, causa: grouped barplot!<br />Io ho il file "stem" di 495 righe e 8 colonne tra cui quelle di mio interesse sono: "Date", "Exp_Flux" e "D". Vorrei tanto fare un barplot in cui sull'asse delle x ci siano le date, sull'asse delle y gli Exp_Flux e le barre dovrebbero essere una per ogni classe diametrica (D).<br />Non riesco proprio a capire come gestire i dati, ho usato il comando cut per creare le classi diametriche<br /><br />bin <- cut(stem$D, breaks = c(5,10,15,20,25,30),include.lowest=TRUE)<br /> cond1 <- cond & (bin == levels(bin)[1])<br />e così via...<br />poi ho usato aggregate per creare degli oggetti che contenessero le medie di 5 misure giornaliera per ogni pianta ma questo script funziona solo se tolgo ":(stem [cond1,"Pianta",])"<br /><br />aggregate (stem [cond1,"Exp_Flux",], by=list(stem[cond1,"Date",]):(stem [cond1,"Pianta",]), mean.na.rm )<br /><br />Comunque è inutile che vado avanti con i 10000 tentativi che ho fatto, non so proprio gestire i barplot, sarà colpa del fatto che sono 10 ore che sto davanti al pc e del tempo che mi corre dietro ma se tu mi dessi qualche suggerimento te ne sarei immensamente grata :) ... come una delle tue commentartrici ha già detto, con excel ci metterei 2 secondi ma proprio non ce la faccio a tornare indietro... Cskenehttps://www.blogger.com/profile/15569292060166258710noreply@blogger.comtag:blogger.com,1999:blog-7556813435224291579.post-69066412498198043152010-04-19T11:44:58.941+01:002010-04-19T11:44:58.941+01:00Very good and Thanks for sharing! :-)Very good and Thanks for sharing! :-)Paolohttps://www.blogger.com/profile/01969817827028660433noreply@blogger.comtag:blogger.com,1999:blog-7556813435224291579.post-35101648577551948972010-04-19T11:28:08.206+01:002010-04-19T11:28:08.206+01:00Done! :-)
barplot(aver2, col=c("green"...Done! :-) <br /><br />barplot(aver2, col=c("green", "blue"), space=0, border=NA, cex.axis=1)<br /><br />axis(1, at=c(0, 10, 20, 30, 40, 47, 51, 55, 65, 75), tck=1, labels= NA)<br /><br />mtext (c("BI", "PT", "AF", "MA", "BC","NA", "SI", "BA", "CR"), side=1, at=c(5, 15, 25, 35, 43, 49, 53, 61, 71), cex=0.8)Consuelohttps://www.blogger.com/profile/03286751213439799209noreply@blogger.comtag:blogger.com,1999:blog-7556813435224291579.post-29093700443035312402010-04-19T10:43:00.839+01:002010-04-19T10:43:00.839+01:00yeap... I'm trying that now, but instead of te...yeap... I'm trying that now, but instead of text, with leyend... I was not able to insert text outside the plot. Thanks Paolo!Consuelohttps://www.blogger.com/profile/03286751213439799209noreply@blogger.comtag:blogger.com,1999:blog-7556813435224291579.post-44447402035299603042010-04-19T10:10:03.474+01:002010-04-19T10:10:03.474+01:00Dear Consu, I think you should set the axisnames p...Dear Consu, I think you should set the axisnames parameter to FALSE then start tinkering the labels using text(). See the examples in ?barplot help page.<br /><br />HIHPaolohttps://www.blogger.com/profile/01969817827028660433noreply@blogger.comtag:blogger.com,1999:blog-7556813435224291579.post-89751491960237166832010-04-19T09:55:16.915+01:002010-04-19T09:55:16.915+01:00well... not the tick lines really, the labels...well... not the tick lines really, the labels...Consuelohttps://www.blogger.com/profile/03286751213439799209noreply@blogger.comtag:blogger.com,1999:blog-7556813435224291579.post-39116468573828850552010-04-19T09:46:56.670+01:002010-04-19T09:46:56.670+01:00You're welcome!! My pleasure!!
By the way, do...You're welcome!! My pleasure!!<br /><br />By the way, do you know how can I change the tick position? my boss told me to move them to the middle!! hahaha!! <br /><br />PS. What were you doing online at 7:30?? sunday morning?Consuelohttps://www.blogger.com/profile/03286751213439799209noreply@blogger.comtag:blogger.com,1999:blog-7556813435224291579.post-66949090686990901712010-04-18T07:30:25.168+01:002010-04-18T07:30:25.168+01:00Dear Consu, very nice contribution! Thank you!Dear Consu, very nice contribution! Thank you!Paolohttps://www.blogger.com/profile/01969817827028660433noreply@blogger.comtag:blogger.com,1999:blog-7556813435224291579.post-46633809515210541252010-04-17T15:51:37.901+01:002010-04-17T15:51:37.901+01:00Hi Paolo!!
The code was really easy at the end, b...Hi Paolo!!<br /><br />The code was really easy at the end, but as usual, it took more than it should have :-)<br /><br />For your data, it would be like this:<br /><br />barplot(height, space=0, border=NA, main="without tick lines")<br /><br />or:<br /><br />barplot(height, space=0, border=NA, main="with tick lines")<br />axis(1, tck=1)<br /><br />In my case, what I wanted was to plot one of the outputs from the Structure software<br />(http://pritch.bsd.uchicago.edu/software/structure2_2.html), like this one:<br />http://img411.imageshack.us/i/barplot.jpg/<br /><br />In that case, the code is like this:<br /><br />barplot("mydata" border=NA, main="barplot like the one produced by Structure software")<br />axis(1, at=c(0, 10, 20, 30, 40, 47, 51, 55, 65, 75), tck=1, labels= c(NA, c(1:9)))<br /><br />I still don't know how to put the labels before the tick line, like in the structure plot, but I don't care that much... <br /><br />Here are the plots: http://img695.imageshack.us/i/onetip.jpg/Consuelohttps://www.blogger.com/profile/03286751213439799209noreply@blogger.comtag:blogger.com,1999:blog-7556813435224291579.post-28218508985851063712010-04-17T08:33:30.411+01:002010-04-17T08:33:30.411+01:00Sono contento che tu sia riuscita a risolvere il t...Sono contento che tu sia riuscita a risolvere il tuo problema da sola! :-)<br />Se hai tempo e volessi condividere il tuo codice con gli altri lettori del blog non esitare a postarlo di seguito!<br />In effetti R, a volte, può risultare un poco stressante! ;-)<br />A tale proposito ti consiglio la lettura di R-Inferno (vedi i links accanto) penso che la troverai molto interessante!Paolohttps://www.blogger.com/profile/01969817827028660433noreply@blogger.comtag:blogger.com,1999:blog-7556813435224291579.post-70859084837534823502010-04-17T01:12:20.237+01:002010-04-17T01:12:20.237+01:00mmmm.... penso che sono riuscita finalmente... che...mmmm.... penso che sono riuscita finalmente... che fastidio a volte!!! :S grazie!!Consuelohttps://www.blogger.com/profile/03286751213439799209noreply@blogger.comtag:blogger.com,1999:blog-7556813435224291579.post-1345006428387816662010-04-17T00:53:06.989+01:002010-04-17T00:53:06.989+01:00Salve Paolo, come stai?
Senti, sono stanca di ten...Salve Paolo, come stai? <br />Senti, sono stanca di tentare a fare un barplot! Con Excel lo faccio subito, ma se lo voglio fare in R... non ci riesco... non capisco come farlo. :( <br />Devo fare un barplot come questo http://img360.imageshack.us/i/barplot.jpg/? Ma se faccio barplot con Stack=TRUE mi viene un graffico tutto diverso! sai come si fa?? non voglio perdere più tempo con questo maledetto barplot hahaha... grazie!!Consuelohttps://www.blogger.com/profile/03286751213439799209noreply@blogger.com