RaoulD
2010-Oct-03 03:57 UTC
[R] Help with panel.text in Lattice - Putting labels for co-oridnates in a plot
Hi, I am trying to create a Lattice dotplot that has the following data graphed. I need to put labels for each of the co-oridnates on the plot. I have managed to get only one label dispalyed as I don't completely understand the "panel.text" function. Can someone please help me? # Sub Reason is a text field that I need to see the volumes for (Vols) dotplot(DU_Summary_plotdata$SubReason ~ DU_Summary_plotdata$Vols ,horiz=TRUE,main="Top Sub-Reasons - Volumes (90% of Volumes)", family="serif",font=2,xlab="Volumes",ylab="Sub-Reasons",labels=DU_Summary_plotdata$Vols,pch=">",cex=1.5, panel = function(x, y, ...) { panel.dotplot(x, y, ...) panel.text(1,2,labels =DU_Summary_plotdata$Vols , pos = 4) }) The dataset DU_Summary_plotdata is made up of: SubReason<-c( SR_1, SR_2 , SR_3, SR_4, SR_5, SR_6, SR_7, SR_8) Vols<-c( 33827,17757,11404,5999,5305,3515,3051,1924) Thanks, Raoul -- View this message in context: http://r.789695.n4.nabble.com/Help-with-panel-text-in-Lattice-Putting-labels-for-co-oridnates-in-a-plot-tp2952919p2952919.html Sent from the R help mailing list archive at Nabble.com.
David Winsemius
2010-Oct-03 16:53 UTC
[R] Help with panel.text in Lattice - Putting labels for co-oridnates in a plot
RaoulD wrote:> > Hi, > > I am trying to create a Lattice dotplot that has the following data > graphed. I need to put labels for each of the co-oridnates on the plot. I > have managed to get only one label dispalyed as I don't completely > understand the "panel.text" function. Can someone please help me? > > # Sub Reason is a text field that I need to see the volumes for (Vols) > > dotplot(DU_Summary_plotdata$SubReason ~ DU_Summary_plotdata$Vols > ,horiz=TRUE,main="Top Sub-Reasons - Volumes (90% of Volumes)", > > family="serif",font=2,xlab="Volumes",ylab="Sub-Reasons",labels=DU_Summary_plotdata$Vols,pch=">",cex=1.5, > panel = function(x, y, ...) { > panel.dotplot(x, y, ...) > panel.text(1,2,labels =DU_Summary_plotdata$Vols , > pos = 4) > }) > > The dataset DU_Summary_plotdata is made up of: > SubReason<-c( SR_1, SR_2 , SR_3, SR_4, SR_5, SR_6, SR_7, SR_8) > Vols<-c( 33827,17757,11404,5999,5305,3515,3051,1924) > > Thanks, > Raoul >Several problems with your example and explanation: 1) It will not run as posted, since your plot call expects that data to be in a dataframe and you only constructed 2 vectors. 2) Even if you naively put the two vectors in a dataframe, the SubReason columns would expect to be able to find objects with those names, so I suspect you should have quoted them. Trying to fix these: DU_Summary_plotdata <- data.frame(SubReason=c( 'SR_1', 'SR_2' , 'SR_3', 'SR_4', 'SR_5', 'SR_6', 'SR_7', 'SR_8'), Vols=c( 33827,17757,11404,5999,5305,3515,3051,1924) ) produced a single text value with a set of eight blue arrows at the indicated horizontal locations. 3) But the panel.text function was only given a single location at which to plot the values. (The interpreter plotted the first value at point (1,2) with left justification.) Trying instead: dotplot(DU_Summary_plotdata$SubReason ~ DU_Summary_plotdata$Vols ,horiz=TRUE,main="Top Sub-Reasons - Volumes (90% of Volumes)", family="serif",font=2,xlab="Volumes",ylab="Sub-Reasons",labels=DU_Summary_plotdata$Vols,pch=">",cex=1.5, panel = function(x, y, ...) { panel.dotplot(x, y, ...) panel.text(DU_Summary_plotdata$Vols, 1:length(DU_Summary_plotdata$SubReason), labels =DU_Summary_plotdata$Vols , pos = 4) }) # you need to offer the x value first and the y-values are ascending integers. It seems close to what you perhaps wanted (but did not really explain very fully). It has the defect that the right-most value is partly off the plot area. That can be remedied by changing the pos=4 argument to pos=1. -- David. -- View this message in context: http://r.789695.n4.nabble.com/Help-with-panel-text-in-Lattice-Putting-labels-for-co-oridnates-in-a-plot-tp2952919p2953317.html Sent from the R help mailing list archive at Nabble.com.