How to add overlapping bar charts

Using the data in this question https://stackoverflow.com/questions/21663108/coloring-points-on-a-lattice-plot-in-r I want to use the function histogramin latticeto build three histograms on the same section, but separately so that I can control the colors and allow a translucent color where the histograms overlap.

However, the following code does not work:

histogram(locs[locs.col=="darkblue"] , breaks=20, xlim=c(25,150),col="darkblue" )
histogram(locs[locs.col=="yellow"] , breeaks=20, xlim=c(25,150),col="yellow",add=T ) # add doesn't work here
histogram(locsy[locs.col=="red"] , breaks=20, xlim=c(25,150),col="red",add=T )

because histograms will not be added to eachother. I know that this works for a function histin basic packages, so here are my questions:

1) Is there a way to add histograms to the chart with histogram? 2) How can I make the histogram bins of the same width for each histogram instance 3) How can I make the colors translucent for where the histograms overlap? 4) How to rotate the histogram 90 degrees so that it is a horizontal axis?

+3
source share
2 answers

The lattice function histogramdoes not support add = T, which is part of the base graphics. In addition, the usual way to get side by side or overlapping graphs in the lattice is the β€œgroups” parameter, and histogram again does not support groups. But the help page says thatdensityplot will be, and it also displays the locations of the data points and accepts the alpha transparency argument:

df <- data.frame(locs=locs, locs.col=locs.col,dataset=dataset)
densityplot(~locs, groups=locs.col,data=df , xlim=c(25,150), alpha=.5 )

enter image description here

If you want your own colors you can try: ...,col=locs.col,...

, , "" :

, ( ) :

http://markmail.org/search/?q=list%3Aorg.r-project.r-help++densityplot+switch+x+y#query:list%3Aorg.r-project.r-help%20%20densityplot%20switch%20x%20y+page:1+mid:oop3shncxgx4mekc+state:results

-------- ------ , . , , "" , "", , breaks = NULL , :

densityplot(~x,data=foo,groups=grp, 
#prepanel=function(x,type,groups,...){???}, 
  panel=function(x,type,groups,...){ 
    panel.densityplot(x,groups=groups,...) 
    panel.histogram(x,col='transparent', breaks = NULL, ...)

} ) 

------- -------

( ), , : http://markmail.org/search/?q=list%3Aorg.r-project.r-help++densityplot+switch+x+y#query:list%3Aorg.r-project.r-help%20%20densityplot%20switch%20x%20y+page:1+mid:fyva5hrio6cn4fs2+state:results

+1

, bwplot , :

histogram( ~Sepal.Length,
     data = iris,
     type = "p",
     breaks = seq(4,8,by=0.2),
     ylim = c(0,30),
     groups = Species,
     panel = function(...)panel.superpose(...,panel.groups=panel.histogram,
                          col=c("cyan","magenta","yellow"),alpha=0.4),
     auto.key=list(columns=3,rectangles=FALSE,
                   col=c("cyan","magenta","yellow3"))
     )

overlapping histograms in R with lattice, Sepal. Length from iris data

+5

All Articles