[R] Comination of two barcharts and one xyplot

stephen sefick ssefick at gmail.com
Wed Aug 13 15:14:54 CEST 2008


not reproducible

On Wed, Aug 13, 2008 at 9:07 AM, ravi <rv15i at yahoo.se> wrote:
> Hi Rhelpers,
> I would like to have some help with a plot which is beyond my capabilities. This plot that I am seeking involves an overlay of two different barcharts and one xyplot.
> The code that I have used is the following :
> #save(df1,file="M:\\KBR\\df1.RData")
> load(file="M:\\KBR\\df1.RData")
> # df1$Year.ord created to obtain the right order i.e. 2015M < 2015K
> Year.ord<-ordered(Year,levels=c('2003','2005','2007','2009','20011','2013','2015M','2015K'))
> # Use reshape package to melt the data frame
> library(reshape)
> df1m<-melt(df1,id=c("Year","Year.ord"))
> library(lattice)
> attach(df1m)
> barchart(value~Year.ord|variable,scales=list(y="free",x=list(rot=90)),xlab="Year",ylab="No. of Tests *1000",col="blue")
> This plot works just fine. But I want to go beyond this. My first data frame (df1) is :
> "Year","KI","G48","AvCell","HB","Htens","Impact","Struct","Tens","Year.ord"
> "1","2003",15.53,0.3,0.24,37.45,0.76,1.16,3.02,34.05,"2003"
> "2","2005",15.64,0.29,0.33,34.64,1.12,1.78,4.2,32.88,"2005"
> "3","2007",16.18,0.49,0.59,30.32,1.63,4.23,6.67,30.06,"2007"
> "4","2009",17.09,0.67,0.91,29.47,2.27,6.76,9.68,29.25,"2009"
> "5","2011",22.39,0.93,1.24,38.03,3.11,9.17,13.18,37.84,"2011"
> "6","2013",33.83,1.29,1.87,58.37,4.43,14.06,19.41,57.6,"2013"
> "7","2015M",44.91,1.83,2.71,75.54,6.28,20.57,27.51,74.5,"2015M"
> "8","2015K",52.22,2.14,3.15,87.71,7.34,23.88,31.98,86.57,"2015K"
> My second data frame is (L1) is :
> "Year","KIL","G48L","AvCellL","HBL","HtensL","ImpactL","StructL","TensL"
> "1",2009,20,1,1,30,2,10,10,35
> "2",2011,24,1,1.5,35,3,12,13,38
> "3",2013,30,1,2,40,4,14,16,45
> What I want, in each panel of the lattice barchart, is to plot histograms of the relevant variable (KI, G48 etc) in one colour for the years 2003 to 2007, and in another colour for the other years. On top of this, I want to have a line plot in each panel with the limits for different years given in the second data frame L1 (as bold lines).
> I would like to have information on the following points :
> 1. How can I get a combination of these plots in every panel (two histograms and one line plot)? Is it possible?
> 2. Is it easier to do this with ggplot?
> 3. I would like to know how I can present the legend also.
> Will appreciate any help that I can get.
>
> Thanking You,
> Ravi
>
>
> ______________________________________________
> R-help at 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.
>



-- 
Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods. We are mammals, and have not exhausted the
annoying little problems of being mammals.

	-K. Mullis



More information about the R-help mailing list