Luis Fernando García
2015-May-05 07:34 UTC
[R] Sort data and symbol change in Jitter plot (ggplot2)
Dear R experts, First than all I want to thank your expertise and for sharing your knowledge with the people who are starting. Recently I have been working on a new plot style (Jitterplot) but have still some issues when making two basic functions. First than all I want to change the symbol according to the prey type (presa) and not the color, I tried making, geom_dotplot(aes(fill = PRESA) but it did not work On a second hand I want to sort the plots from the highest to the lowest value, I tried by using reorder, but it did not work. Please find attached the dataset and the script. Thanks in advance! ####script###### the dataset is attached library(ggplot2) p=read.table("paratropis.txt",header=T) attach(p) ggplot( data = p, aes(y = Tiempo, x = PRESA, reorder(PRESA, Tiempo, mean))) + # Move y and x here so than they can be used in stat_* geom_dotplot(aes(shape = PRESA), binaxis = "y", # which axis to bin along binwidth = 0.1, # Minimal difference considered diffeerent stackdir = "center" # Centered ) + stat_summary(fun.y = mean, fun.ymin = mean, fun.ymax = mean, geom = "crossbar", width = 0.5) -------------- next part -------------- Ara?a PRESA TAMA?O Tiempo Ara1 L.lepi peque?o 255506 Ara2 L.passa grande 439724 Ara3 L.cicin peque?o 408377 Ara3 L.passa grande 268235 Ara3 L.passa peque?o 419578 Ara3 L.rute peque?o 427730 Ara3 L.lepi grande 351840 Ara4 L.cicin peque?o 548918 Ara4 L.passa peque?o 438361 Ara4 L.rute grande 903518 Ara4 L.rute peque?o 359928 Ara4 L.lepi grande 332754 Ara4 L.lepi peque?o 267759 Ara6 L.rute peque?o 227514 Ara7 L.cicin peque?o 494398 Ara7 L.passa grande 218080 Ara7 L.rute grande 485121 Ara7 L.rute peque?o 498692 Ara7 L.lepi grande 248303 Ara7 L.lepi peque?o 101027 Ara8 L.lepi grande 320952 Ara9 L.cicin grande 334014 Ara9 L.cicin peque?o 232391 Ara9 L.passa peque?o 447254 Ara9 L.rute grande 533385 Ara9 L.rute peque?o 864524 Ara9 L.lepi grande 282418 Ara9 L.lepi peque?o 169500 Ara10 L.cicin grande 476236 Ara10 L.cicin peque?o 377899 Ara10 L.rute peque?o 426247 Ara11 L.passa grande 286441 Ara11 L.rute peque?o 544675 Ara11 L.lepi grande 397056 Ara12 L.passa grande 217148 Ara12 L.rute grande 438068 Ara12 L.lepi grande 389474 Ara14 L.cicin grande 513290 Ara14 L.passa grande 356091 Ara15 L.cicin peque?o 511906 Ara16 L.cicin peque?o 790962 Ara16 L.passa grande 507399 Ara16 L.rute peque?o 298853 Ara17 L.cicin grande 468640 Ara17 L.rute peque?o 392512 Ara18 L.rute peque?o 473115 Ara19 L.cicin grande 578176 Ara19 L.cicin peque?o 479934 Ara19 L.passa peque?o 319707 Ara19 L.rute grande 347096 Ara21 L.cicin grande 546950 Ara23 L.cicin grande 371814 Ara23 L.passa grande 287769 Ara23 L.passa peque?o 281093 Ara23 L.rute grande 429621 Ara23 L.lepi grande 208509 Ara24 L.cicin grande 393763 Ara25 L.cicin grande 469052 Ara25 L.lepi grande 410563 Ara25 L.lepi peque?o 439584 Ara26 L.cicin peque?o 485701 Ara26 L.rute grande 391971 Ara27 L.cicin grande 491197 Ara28 L.passa peque?o 308984 Ara29 L.lepi peque?o 472830 Ara30 L.passa peque?o 249036 Ara31 L.passa grande 217148 Ara31 L.passa peque?o 212454 Ara31 L.lepi peque?o 234619 Ara32 L.passa peque?o 230255 Ara32 L.lepi peque?o 297512 Ara34 L.rute grande 352213 Ara34 L.passa peque?o 191547 Ara34 L.lepi peque?o 201616 Ara36 L.lepi grande 411587
Hi answeres in line> -----Original Message----- > From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Luis > Fernando Garc?a > Sent: Tuesday, May 05, 2015 9:34 AM > To: r-help at r-project.org > Subject: [R] Sort data and symbol change in Jitter plot (ggplot2) > > Dear R experts, > > First than all I want to thank your expertise and for sharing your > knowledge with the people who are starting. > > Recently I have been working on a new plot style (Jitterplot) but have > still some issues when making two basic functions. > > First than all I want to change the symbol according to the prey type > (presa) and not the color, I tried making, geom_dotplot(aes(fill > PRESA) > but it did not work > > On a second hand I want to sort the plots from the highest to the > lowest > value, I tried by using reorder, but it did not work. > > Please find attached the dataset and the script. > > Thanks in advance! > > ####script###### > > the dataset is attached > library(ggplot2) > p=read.table("paratropis.txt",header=T) > attach(p)Do not use attach, it only confuses things. firs reorder your factor p$PRESA <- reorder(p$PRESA, p$Tiempo, mean) then use geom point to get different shapes. pl<-ggplot( data = p, aes(y = Tiempo, x = PRESA, shape=PRESA)) pl + geom_point()+ geom_dotplot(binaxis = "y", binwidth = 0.1, stackdir = "center") + stat_summary(fun.y = mean, fun.ymin = mean, fun.ymax = mean, geom = "crossbar", width = 0.5) Is this what you wanted? Cheers Petr> ggplot( data = p, aes(y = Tiempo, x = PRESA, reorder(PRESA, Tiempo, > mean))) > + # Move y and x here so than they can be used in stat_* > geom_dotplot(aes(shape = PRESA), > binaxis = "y", # which axis to bin along > binwidth = 0.1, # Minimal difference considered > diffeerent > stackdir = "center" # Centered > ) + > stat_summary(fun.y = mean, fun.ymin = mean, fun.ymax = mean, > geom = "crossbar", width = 0.5)________________________________ Tento e-mail a jak?koliv k n?mu p?ipojen? dokumenty jsou d?v?rn? a jsou ur?eny pouze jeho adres?t?m. Jestli?e jste obdr?el(a) tento e-mail omylem, informujte laskav? neprodlen? jeho odes?latele. Obsah tohoto emailu i s p??lohami a jeho kopie vyma?te ze sv?ho syst?mu. Nejste-li zam??len?m adres?tem tohoto emailu, nejste opr?vn?ni tento email jakkoliv u??vat, roz?i?ovat, kop?rovat ?i zve?ej?ovat. Odes?latel e-mailu neodpov?d? za eventu?ln? ?kodu zp?sobenou modifikacemi ?i zpo?d?n?m p?enosu e-mailu. V p??pad?, ?e je tento e-mail sou??st? obchodn?ho jedn?n?: - vyhrazuje si odes?latel pr?vo ukon?it kdykoliv jedn?n? o uzav?en? smlouvy, a to z jak?hokoliv d?vodu i bez uveden? d?vodu. - a obsahuje-li nab?dku, je adres?t opr?vn?n nab?dku bezodkladn? p?ijmout; Odes?latel tohoto e-mailu (nab?dky) vylu?uje p?ijet? nab?dky ze strany p??jemce s dodatkem ?i odchylkou. - trv? odes?latel na tom, ?e p??slu?n? smlouva je uzav?ena teprve v?slovn?m dosa?en?m shody na v?ech jej?ch n?le?itostech. - odes?latel tohoto emailu informuje, ?e nen? opr?vn?n uzav?rat za spole?nost ??dn? smlouvy s v?jimkou p??pad?, kdy k tomu byl p?semn? zmocn?n nebo p?semn? pov??en a takov? pov??en? nebo pln? moc byly adres?tovi tohoto emailu p??padn? osob?, kterou adres?t zastupuje, p?edlo?eny nebo jejich existence je adres?tovi ?i osob? j?m zastoupen? zn?m?. This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients. If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system. If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner. The sender of this e-mail shall not be liable for any possible damage caused by modifications of the e-mail or by delay with transfer of the email. In case that this e-mail forms part of business dealings: - the sender reserves the right to end negotiations about entering into a contract in any time, for any reason, and without stating any reasoning. - if the e-mail contains an offer, the recipient is entitled to immediately accept such offer; The sender of this e-mail (offer) excludes any acceptance of the offer on the part of the recipient containing any amendment or variation. - the sender insists on that the respective contract is concluded only upon an express mutual agreement on all its aspects. - the sender of this e-mail informs that he/she is not authorized to enter into any contracts on behalf of the company except for cases in which he/she is expressly authorized to do so in writing, and such authorization or power of attorney is submitted to the recipient or the person represented by the recipient, or the existence of such authorization is known to the recipient of the person represented by the recipient.
Luis Fernando García
2015-May-07 06:51 UTC
[R] Sort data and symbol change in Jitter plot (ggplot2)
Thanks all of you guys! Your answers were very useful! Thanks for the answer John, but I will try to keep the dotplot, but it is very useful to know both techniques anyway :) Petr, many thanks for your help, it was just what I needed, btw, the arrangment based on the median was a headache for me! again, thanks!!! 2015-05-05 4:34 GMT-03:00 Luis Fernando Garc?a <luysgarcia at gmail.com>:> Dear R experts, > > First than all I want to thank your expertise and for sharing your > knowledge with the people who are starting. > > Recently I have been working on a new plot style (Jitterplot) but have > still some issues when making two basic functions. > > First than all I want to change the symbol according to the prey type > (presa) and not the color, I tried making, geom_dotplot(aes(fill = PRESA) > but it did not work > > On a second hand I want to sort the plots from the highest to the lowest > value, I tried by using reorder, but it did not work. > > Please find attached the dataset and the script. > > Thanks in advance! > > ####script###### > > the dataset is attached > library(ggplot2) > p=read.table("paratropis.txt",header=T) > attach(p) > ggplot( data = p, aes(y = Tiempo, x = PRESA, reorder(PRESA, Tiempo, > mean))) + # Move y and x here so than they can be used in stat_* > geom_dotplot(aes(shape = PRESA), > binaxis = "y", # which axis to bin along > binwidth = 0.1, # Minimal difference considered > diffeerent > stackdir = "center" # Centered > ) + > stat_summary(fun.y = mean, fun.ymin = mean, fun.ymax = mean, > geom = "crossbar", width = 0.5) > > >[[alternative HTML version deleted]]