[R] graph: horizontal bar reflecting number of data

Ulrik Stervbo ulrik.stervbo at gmail.com
Fri Jul 15 09:31:17 CEST 2016


Dear Dagmar,

must the numberdata be character?

Here are tew solutions. The first solution summarise before plotting and
the second does everything in the plot

library("dplyr")
library("ggplot2")
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 %>% group_by(week) %>% summarise(numberdata.sum = sum(numberdata))
%>%
ggplot() +
aes(x = week, y = numberdata.sum) +
geom_bar(stat = "identity")

ggplot(datframe) +
aes(x = week, y = ..count.., weights = numberdata) +
geom_bar()

Hope this helps
Ulrik

On Fri, 15 Jul 2016 at 09:18 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))
>
> ______________________________________________
> 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.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list