Reputation: 61
I am trying to create a barchart for the number of passes per date for 3 sites. Here is my initial working:
Test <- read.csv("Test.csv")
head(Test)
str(Test)
> head(Test)
Date Site Passes
1 20111223 Met Mast 10m 8
2 20111224 Met Mast 10m 4
3 20111225 Met Mast 10m 27
4 20111226 Met Mast 10m 4
5 20111227 Met Mast 10m 20
6 20111228 Met Mast 10m 11
> str(Test)
'data.frame': 26 obs. of 3 variables:
$ Date : int 20111223 20111224 20111225 20111226 20111227 20111228 20111229
20111230 20111231 20111223 ...
$ Site : Factor w/ 3 levels "Control","Met Mast 10m",..: 2 2 2 2 2 2 2 2 2 3 ...
$ Passes: int 8 4 27 4 20 11 17 0 41 6 ...
I am using ggplot so I load the library and use qplot:
library(ggplot2)
qplot(Date, data=Test, geom ="bar", position="dodge", fill=Site, binwidth=0.5,
weight = Passes) +
scale_y_continuous("Number of Passes")
I get a perfect graph (sorry I cant post an image) thats exactly what I want with date on the x-axis, number of passes on the y-axis, and the 3 factors plotted side-by-side next to each other for each date with a legend.
I tested my method and code on a subset of my data (i.e. only 26 observations) to make sure it works which it did. Now I want to plot the same graph for all of my data which consists of 97 observations.
The issue:
When I run the code for all my data the output is a blank graph with correctly labeled axes and legend. On the x-axis the date format changed from the usuall 20111223 to 20112500 which is non-sensical and I dont know why.
Ive read many of the ggplot2 and qplot questions on this forum but I have not found anyone who has had a similar issue. Because I got the plot to work with few data points I think it may be an issue of the x-axis scale but Im not sure. Why is the plot blank?
Please help :)
> dput(Test)
structure(list(Date = c(20111223L, 20111224L, 20111225L, 20111226L,
20111227L, 20111228L, 20111229L, 20111230L, 20111231L, 20120101L,
20120102L, 20120103L, 20120104L, 20120105L, 20120106L, 20120107L,
20120108L, 20120109L, 20120110L, 20120111L, 20120112L, 20120113L,
20120114L, 20120115L, 20120116L, 20120117L, 20120118L, 20120119L,
20120120L, 20120121L, 20120122L, 20120123L, 20120124L, 20120125L,
20120126L, 20120127L, 20111223L, 20111224L, 20111225L, 20111226L,
20111227L, 20111228L, 20111229L, 20111230L, 20111231L, 20120101L,
20120102L, 20120103L, 20120104L, 20120105L, 20120106L, 20120107L,
20120108L, 20120109L, 20120110L, 20120111L, 20120112L, 20120113L,
20120114L, 20120115L, 20120116L, 20120117L, 20120118L, 20120119L,
20120120L, 20120121L, 20120122L, 20120123L, 20120124L, 20120125L,
20120126L, 20120127L, 20111222L, 20111223L, 20111224L, 20111225L,
20111226L, 20111227L, 20111228L, 20111229L, 20111230L, 20111231L,
20120101L, 20120102L, 20120103L, 20120104L, 20120105L, 20120106L,
20120107L, 20120108L, 20120109L, 20120110L, 20120111L, 20120112L,
20120113L, 20120114L, 20120115L), Site = structure(c(2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Control",
"Met Mast 10m", "Met Mast 17m"), class = "factor"), Passes = c(8L,
4L, 27L, 4L, 20L, 11L, 17L, 0L, 41L, 6L, 9L, 29L, 38L, 5L, 38L,
12L, 6L, 14L, 18L, 35L, 36L, 8L, 23L, 25L, 0L, 0L, 0L, 37L, 53L,
59L, 205L, 15L, 2L, 14L, 6L, 6L, 6L, 6L, 29L, 4L, 26L, 12L, 12L,
3L, 21L, 20L, 17L, 31L, 79L, 10L, 59L, 12L, 6L, 18L, 21L, 27L,
31L, 14L, 40L, 37L, 0L, 0L, 0L, 52L, 52L, 63L, 0L, 30L, 2L, 14L,
14L, 4L, 41L, 296L, 115L, 470L, 171L, 589L, 96L, 306L, 44L, 131L,
244L, 75L, 217L, 252L, 304L, 313L, 250L, 315L, 121L, 298L, 247L,
222L, 161L, 335L, 173L)), .Names = c("Date", "Site", "Passes"
), class = "data.frame", row.names = c(NA, -97L))
Upvotes: 0
Views: 215
Reputation: 11
If it works for a subset of your data, it is most likely that there is somehting unexpected in your data (NA's, etc). It's not possible to know exactly what is going on without seeing the data. If you provide the data with dput(data)
, you may get a better answer.
Upvotes: 1