[R] graph: horizontal bar reflecting number of data

Jim Lemon drjimlemon at gmail.com
Fri Jul 15 10:27:34 CEST 2016


Hi Dagmar,
Maybe your want something like this?

datframe<-data.frame(Name=c("Kati","Kati","Kati","Leon","Leon","Leon" ),
 week =c("1","2", "3", "1","2", "3"),
 numberdata =c("5","12", "1", "6","2", "5"))
datframe
datframe$numberdata<-as.numeric(as.character(datframe$numberdat))
library(plotrix)
barcol<-color.scale(datframe$numberdat,extremes=c("blue","red"))
barpos<-barplot(matrix(datframe$numberdat,nrow=2,byrow=TRUE),
  beside=TRUE,names.arg=paste("Week",1:3),ylim=c(0,13),
  col=matrix(barcol,nrow=2,byrow=TRUE))
barlabels(barpos,matrix(datframe$numberdat,nrow=2,byrow=TRUE))
barlabels(barpos,matrix(datframe$numberdat+0.4,nrow=2,byrow=TRUE),
 labels=rep(c("Kati","Leon"),3),prop=1)

I don't see any other way to put the names on the y-axis that makes any sense.

Jim


On Fri, Jul 15, 2016 at 5:14 PM, Dagmar <Ramgad82 at gmx.net> wrote:
> Dear all, dear Jim,
>
> Thank you for trying to help Jim. Unfortunately it didn't solve my problem.
>
> I want the names of the weeks on the x axis and the animals on the y-axis.
>
> Then, the shading of the barplot is supposed to represent the number of data
> per week.
>
> Any help?
>
> Dagmar
>
>
> Am 13.07.2016 um 13:58 schrieb Jim Lemon:
>>
>> datframe$numberdata<-as.numeric(as.character(datframe$numberdat))
>> library(plotrix)
>> barcol<-color.scale(datframe$numberdat,extremes=c("black","white"))
>> barplot(matrix(datframe$numberdat,nrow=2,byrow=TRUE),
>>   beside=TRUE, horiz=TRUE,names.arg=paste("Week",1:3),
>>   col=matrix(barcol,nrow=2,byrow=TRUE))
>
>



More information about the R-help mailing list