English 中文(简体)
就业问题
原标题:Barplot beside issue
  • 时间:2012-04-26 19:51:10
  •  标签:
  • r
  • plot

我设法将一些数据汇总到以下几个方面:

   Month Year Number
1     1  2011   3885
2     2  2011   3713
3     3  2011   6189
4     4  2011   3812
5     5  2011    916
6     6  2011   3813
7     7  2011   1324
8     8  2011   1905
9     9  2011   5078
10   10  2011   1587
11   11  2011   3739
12   12  2011   3560
13    1  2012   1790
14    2  2012   1489
15    3  2012   1907
16    4  2012   1615

我正试图在几个月的酒吧相互交接的地方制造一个酒吧,例如,1月至4月将有两个酒吧(2011年一个,2012年一个),其余几个月只有一个酒吧代表2011年。

我知道我必须使用<代码>beside=T,但我相信,我需要建立某种矩阵,以便让酒吧能够适当展示。 我正在提出一个问题,阐述这一步骤。 我感觉到这可能涉及<条码>矩阵<>,但出于某种原因,我完全放弃了似乎非常简单的解决办法。

此外,我有以下数据:y=c(Jan , Feb , Mar , Apr , May , Jun , Jul , Aug , Sep , Oct , Nov , Dec ,我想用我的名字使用。 当我试图使用上述数据时,我告诉我,我所选择的栏目不明确,这意味着我需要<代码>y中的16个变量。 我如何确定这一点?

最佳回答

使用<条码> 限值 您需要重新安排数据:

dat <- read.table(text = "   Month Year Number
1     1  2011   3885
2     2  2011   3713
3     3  2011   6189
4     4  2011   3812
5     5  2011    916
6     6  2011   3813
7     7  2011   1324
8     8  2011   1905
9     9  2011   5078
10   10  2011   1587
11   11  2011   3739
12   12  2011   3560
13    1  2012   1790
14    2  2012   1489
15    3  2012   1907
16    4  2012   1615",sep = "",header = TRUE)

y <- c( Jan , Feb , Mar , Apr , May , Jun , Jul , Aug , Sep , Oct , Nov , Dec )

barplot(rbind(dat$Number[1:12],c(dat$Number[13:16],rep(NA,8))),
        beside = TRUE,names.arg = y)

“entergraph

或可使用ggplot2,其数据大致如下:

dat$Year <- factor(dat$Year)
dat$Month <- factor(dat$Month)
ggplot(dat,aes(x = Month,y = Number,fill = Year)) + 
    geom_bar(position = "dodge") + 
    scale_x_discrete(labels = y)

“enterography

问题回答

暂无回答




相关问题
How to plot fitted model over observed time series

This is a really really simple question to which I seem to be entirely unable to get a solution. I would like to do a scatter plot of an observed time series in R, and over this I want to plot the ...

REvolution for R

since the latest Ubuntu release (karmic koala), I noticed that the internal R package advertises on start-up the REvolution package. It seems to be a library collection for high-performance matrix ...

R - capturing elements of R output into text files

I am trying to run an analysis by invoking R through the command line as follows: R --no-save < SampleProgram.R > SampleProgram.opt For example, consider the simple R program below: mydata =...

R statistical package: wrapping GOFrame objects

I m trying to generate GOFrame objects to generate a gene ontology mapping in R for unsupported organisms (see http://www.bioconductor.org/packages/release/bioc/vignettes/GOstats/inst/doc/...

Changing the order of dodged bars in ggplot2 barplot

I have a dataframe df.all and I m plotting it in a bar plot with ggplot2 using the code below. I d like to make it so that the order of the dodged bars is flipped. That is, so that the bars labeled "...

Strange error when using sparse matrices and glmnet

I m getting a weird error when training a glmnet regression. invalid class "dgCMatrix" object: length(Dimnames[[2]]) must match Dim[2] It only happens occasionally, and perhaps only under larger ...

Generating non-duplicate combination pairs in R

Sorry for the non-descriptive title but I don t know whether there s a word for what I m trying to achieve. Let s assume that I have a list of names of different classes like c( 1 , 2 , 3 , 4 ) ...

Per panel smoothing in ggplot2

I m plotting a group of curves, using facet in ggplot2. I d like to have a smoother applied to plots where there are enough points to smooth, but not on plots with very few points. In particular I d ...

热门标签