Hello, I have created a boxplot with the data points overlayed on top using
the below code. I am happy with the way the datapoints are jittered, however
I cannot figure out how to get the labels to jitter along with the
datapoints. The labels remain in the center and are unreadable. I have tried
a lot of different ways to get them to jitter but can't seem to make it
work. I have also tried making the label font smaller, but they still
overlap too much. Note I cannot use the method of assigning the lcoation of
each label - there are too many and this graph will be updated frequently
with new data. I greatly appreciate your help. Thanks.
After reading in data...
#load packages
library(ggplot2)
#change letter to factor
df$Letter<-as.factor(df$Letter)
#create boxplot
plot<-qplot(Letter,Number,data=df,geom=c("boxplot","jitter"),fill=Letter)
#Add formatting
plot<-plot + geom_text(aes(label=Identifier),size=3)
ggsave(filename="Spreads
Plot.pdf",plot=plot,width=11,height=8,units="in")
Result:
<http://r.789695.n4.nabble.com/file/n4712380/PostPic.png>
Sample Data:
Identifier Letter Number
AB AA- 46.74
BC A 59.62
CD A 61.63
DE A 69.49
EF A+ 69.73
FG A+ 74.57
GH A 75.01
HI A 77.52
IJ A 77.52
JK A 80.12
KL A 80.14
LM A- 80.35
MN A 81.98
NO A- 82.72
OP A+ 83.56
PQ A 85.29
QR A- 85.46
RS A- 85.92
ST A 86.11
TU A- 86.55
UV A 86.57
VW A 88.32
WX A 89.4
XY A- 96.81
YZ A+ 97.6
BA A- 101.86
CB A 102.37
DC A 104.29
ED A 104.92
FE A 106.29
GF A- 111.84
HG A+ 121.91
IH A- 123.64
--
View this message in context:
http://r.789695.n4.nabble.com/Need-data-labels-to-jitter-with-datapoints-in-boxplot-tp4712380.html
Sent from the R help mailing list archive at Nabble.com.
PIKAL Petr
2015-Sep-18 11:06 UTC
[R] Need data labels to jitter with datapoints in boxplot
Hi
What about to get rid of points jittering and let text labels jitter instead.
plot<-qplot(Letter,Number,data=test,geom=c("boxplot"),fill=Letter)
plot + geom_text(aes(label=Identifier),size=3, position = position_jitter(w =
0.3))
Cheers
Petr
> -----Original Message-----
> From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of smheas
> Sent: Thursday, September 17, 2015 5:21 PM
> To: r-help at r-project.org
> Subject: [R] Need data labels to jitter with datapoints in boxplot
>
> Hello, I have created a boxplot with the data points overlayed on top
> using the below code. I am happy with the way the datapoints are
> jittered, however I cannot figure out how to get the labels to jitter
> along with the datapoints. The labels remain in the center and are
> unreadable. I have tried a lot of different ways to get them to jitter
> but can't seem to make it work. I have also tried making the label font
> smaller, but they still overlap too much. Note I cannot use the method
> of assigning the lcoation of each label - there are too many and this
> graph will be updated frequently with new data. I greatly appreciate
> your help. Thanks.
>
> After reading in data...
>
> #load packages
> library(ggplot2)
> #change letter to factor
> df$Letter<-as.factor(df$Letter)
> #create boxplot
> plot<-
>
qplot(Letter,Number,data=df,geom=c("boxplot","jitter"),fill=Letter)
> #Add formatting
> plot<-plot + geom_text(aes(label=Identifier),size=3)
> ggsave(filename="Spreads
> Plot.pdf",plot=plot,width=11,height=8,units="in")
>
> Result:
> <http://r.789695.n4.nabble.com/file/n4712380/PostPic.png>
>
> Sample Data:
> Identifier Letter Number
> AB AA- 46.74
> BC A 59.62
> CD A 61.63
> DE A 69.49
> EF A+ 69.73
> FG A+ 74.57
> GH A 75.01
> HI A 77.52
> IJ A 77.52
> JK A 80.12
> KL A 80.14
> LM A- 80.35
> MN A 81.98
> NO A- 82.72
> OP A+ 83.56
> PQ A 85.29
> QR A- 85.46
> RS A- 85.92
> ST A 86.11
> TU A- 86.55
> UV A 86.57
> VW A 88.32
> WX A 89.4
> XY A- 96.81
> YZ A+ 97.6
> BA A- 101.86
> CB A 102.37
> DC A 104.29
> ED A 104.92
> FE A 106.29
> GF A- 111.84
> HG A+ 121.91
> IH A- 123.64
>
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Need-data-
> labels-to-jitter-with-datapoints-in-boxplot-tp4712380.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
________________________________
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.
MacQueen, Don
2015-Sep-18 15:01 UTC
[R] Need data labels to jitter with datapoints in boxplot
How about jittering outside the plot? That is, insert df$jNum <- jitter(df$Number) somewhere before the plot commands, then use jNum in your plots instead of Number. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 9/17/15, 8:20 AM, "R-help on behalf of smheas" <r-help-bounces at r-project.org on behalf of sheasley at aegonusa.com> wrote:>Hello, I have created a boxplot with the data points overlayed on top >using >the below code. I am happy with the way the datapoints are jittered, >however >I cannot figure out how to get the labels to jitter along with the >datapoints. The labels remain in the center and are unreadable. I have >tried >a lot of different ways to get them to jitter but can't seem to make it >work. I have also tried making the label font smaller, but they still >overlap too much. Note I cannot use the method of assigning the lcoation >of >each label - there are too many and this graph will be updated frequently >with new data. I greatly appreciate your help. Thanks. > >After reading in data... > >#load packages >library(ggplot2) >#change letter to factor >df$Letter<-as.factor(df$Letter) >#create boxplot >plot<-qplot(Letter,Number,data=df,geom=c("boxplot","jitter"),fill=Letter) >#Add formatting >plot<-plot + geom_text(aes(label=Identifier),size=3) >ggsave(filename="Spreads Plot.pdf",plot=plot,width=11,height=8,units="in") > >Result: ><http://r.789695.n4.nabble.com/file/n4712380/PostPic.png> > >Sample Data: >Identifier Letter Number >AB AA- 46.74 >BC A 59.62 >CD A 61.63 >DE A 69.49 >EF A+ 69.73 >FG A+ 74.57 >GH A 75.01 >HI A 77.52 >IJ A 77.52 >JK A 80.12 >KL A 80.14 >LM A- 80.35 >MN A 81.98 >NO A- 82.72 >OP A+ 83.56 >PQ A 85.29 >QR A- 85.46 >RS A- 85.92 >ST A 86.11 >TU A- 86.55 >UV A 86.57 >VW A 88.32 >WX A 89.4 >XY A- 96.81 >YZ A+ 97.6 >BA A- 101.86 >CB A 102.37 >DC A 104.29 >ED A 104.92 >FE A 106.29 >GF A- 111.84 >HG A+ 121.91 >IH A- 123.64 > > > > >-- >View this message in context: >http://r.789695.n4.nabble.com/Need-data-labels-to-jitter-with-datapoints-i >n-boxplot-tp4712380.html >Sent from the R help mailing list archive at Nabble.com. > >______________________________________________ >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >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.
Thank you both for your responses! I ended up going with PIKAL Petr's suggestion. -- View this message in context: http://r.789695.n4.nabble.com/Need-data-labels-to-jitter-with-datapoints-in-boxplot-tp4712380p4712605.html Sent from the R help mailing list archive at Nabble.com.