Count UNIQUE points within each grid box - r

I have the following data:
EDIT: With smaller sample data
dat <- structure(list(SN = c(198305L, 198305L, 198305L, 198305L,
198305L,198305L, 198305L, 198305L, 198305L, 198305L, 198305L,
198305L, 198305L, 198305L, 198305L, 198305L, 198305L, 198305L,
198305L, 198305L, 198305L, 198305L, 198305L, 198305L, 198305L,
198305L, 198305L, 198305L, 198305L, 198305L, 198305L, 198305L,
198305L, 198305L, 198305L, 198306L, 198306L, 198306L, 198306L,
198308L, 198308L, 198308L, 198308L, 198308L, 198308L, 198308L,
198308L, 198308L, 198308L, 198308L, 198308L, 198308L, 198308L,
198308L, 198308L, 198308L, 198308L, 198308L, 198308L, 198308L,
198308L, 198308L, 198308L, 198310L, 198310L, 198310L, 198310L,
198310L, 198310L, 198310L, 198310L, 198310L, 198310L, 198310L,
198310L, 198310L, 198310L, 198310L, 198310L, 198310L, 198310L,
198310L, 198310L, 198310L, 198310L, 198310L, 198310L, 198310L,
198310L), CY = c(5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L), Year = c(1983L, 1983L, 1983L, 1983L, 1983L, 1983L,
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L,
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L,
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L,
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L,
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L,
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L,
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L,
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L,
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L,
1983L, 1983L), Month = c(8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L
), Day = c(9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 11L, 11L, 11L,
11L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 14L, 14L, 14L, 14L,
15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 17L, 17L, 17L, 14L, 14L,
14L, 14L, 19L, 19L, 19L, 19L, 20L, 20L, 20L, 20L, 21L, 21L, 22L,
22L, 23L, 23L, 23L, 23L, 24L, 24L, 24L, 24L, 25L, 25L, 25L, 25L,
1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, 5L,
5L, 5L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L), Hour = c(0L, 6L, 12L,
18L, 0L, 6L, 12L, 18L, 0L, 6L, 12L, 18L, 0L, 6L, 12L, 18L, 0L,
6L, 12L, 18L, 0L, 6L, 12L, 18L, 0L, 6L, 12L, 18L, 0L, 6L, 12L,
18L, 0L, 6L, 12L, 0L, 6L, 12L, 18L, 0L, 6L, 12L, 18L, 0L, 6L,
12L, 18L, 0L, 6L, 12L, 18L, 0L, 6L, 12L, 18L, 0L, 6L, 12L, 18L,
0L, 6L, 12L, 18L, 0L, 6L, 0L, 6L, 12L, 18L, 0L, 6L, 12L, 18L,
0L, 6L, 12L, 18L, 0L, 6L, 12L, 18L, 0L, 6L, 12L, 18L, 0L, 6L,
12L, 18L), Lat = c(17.8, 18.1, 18.7, 18.9, 19.2, 19.5, 19.9,
20.1, 20.6, 21.2, 21.6, 22, 22.5, 22.9, 23.4, 23.9, 24.6, 24.9,
25.4, 26.1, 26.6, 27.2, 27.6, 28.1, 28.5, 29.1, 29.5, 30, 31.1,
31.8, 32.7, 33.8, 34.6, 35.1, 35.6, 19.8, 19.9, 19.9, 20.2, 15.9,
16.1, 16.3, 16.5, 16.9, 17.4, 18, 18.7, 19.3, 20, 23.8, 24.2,
24.9, 25.4, 25.8, 25.5, 25.1, 25.3, 25.8, 26.2, 26.5, 27.1, 27.9,
29.1, 10.3, 10.2, 9, 9.2, 9.2, 9.5, 10, 10.5, 10.9, 11.3, 12.3,
13, 13.7, 14.4, 15, 15.9, 16.8, 17.2, 17.8, 18.3, 18.7, 19, 19.3,
19.5, 19.7, 20), Lon = c(130.8, 130.7, 130.3, 130.4, 130.4, 130.4,
130.5, 130.5, 130.7, 130.8, 130.7, 130.6, 130.7, 130.8, 131.2,
131.5, 131.8, 132.2, 132.6, 133, 133.3, 133.5, 133.5, 133.5,
133.6, 134.1, 134.3, 134.8, 135.1, 135.8, 136.5, 137, 137.3,
138.1, 139.4, 121.5, 122.7, 124.4, 126.2, 133.8, 133.2, 132.8,
132.4, 132.2, 132.5, 133, 133.7, 134.7, 135.6, 140.1, 141.6,
142.6, 143.1, 143.5, 144, 144.3, 144.7, 144.7, 144.1, 143.4,
142.8, 141.8, 141.3, 151.2, 149.2, 143.4, 141.8, 140.2, 138.9,
137.5, 136, 134.4, 133, 131.7, 130.7, 129.6, 128.8, 128, 126.9,
125.8, 125.1, 124.1, 123.2, 122.2, 121.2, 120.2, 119.2, 118.3,
117.5), VMax = c(145L, 135L, 125L, 120L, 120L, 120L, 115L, 110L,
110L, 115L, 120L, 120L, 120L, 120L, 125L, 120L, 115L, 110L, 105L,
105L, 110L, 100L, 100L, 95L, 90L, 85L, 85L, 80L, 75L, 70L, 70L,
70L, 60L, 55L, 45L, 35L, 40L, 45L, 40L, 35L, 40L, 45L, 50L, 55L,
50L, 45L, 40L, 35L, 35L, 35L, 45L, 50L, 50L, 45L, 40L, 40L, 45L,
50L, 50L, 50L, 45L, 40L, 35L, 35L, 35L, 35L, 40L, 45L, 50L, 55L,
60L, 65L, 70L, 75L, 85L, 90L, 95L, 95L, 95L, 95L, 100L, 120L,
125L, 120L, 100L, 90L, 85L, 85L, 80L), Cat = structure(c(5L,
4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 3L,
4L, 4L, 4L, 3L, 2L, 2L, 2L, 1L), .Label = c("Cat1", "Cat2", "Cat3",
"Cat4", "Cat5", "TS"), class = "factor")), row.names = c(243L,
244L, 245L, 246L, 247L, 248L, 249L, 250L, 251L, 252L, 253L, 254L,
255L, 256L, 257L, 258L, 259L, 260L, 261L, 262L, 263L, 264L, 265L,
266L, 267L, 268L, 269L, 270L, 271L, 272L, 273L, 274L, 275L, 276L,
277L, 278L, 279L, 280L, 281L, 282L, 283L, 284L, 285L, 286L, 287L,
288L, 289L, 290L, 291L, 292L, 293L, 294L, 295L, 296L, 297L, 298L,
299L, 300L, 301L, 302L, 303L, 304L, 305L, 927L, 928L, 929L, 930L,
931L, 932L, 933L, 934L, 935L, 936L, 937L, 938L, 939L, 940L, 941L,
942L, 943L, 944L, 945L, 946L, 947L, 948L, 949L, 950L, 951L, 952L
), class = "data.frame")
Each lat-lon pair has a unique identifier, the SN column.
I created a grid and I want to count the number of unique lat-lon pairs within each grid.
Here's my script:
latmin=0
latmax=50
lonmin=60
lonmax=180
dlat=2.5
dlon=2.5
latint=dlat*0.5
lonint=dlon*0.5
## derive center lat and lon points
x.Lon<-seq((lonmin+lonint),(lonmax-lonint),lonint)
y.Lat<-seq((latmin+latint),(latmax-latint),latint)
df2<-as.data.frame(expand.grid(x.Lon=x.Lon,y.Lat=y.Lat))
df2$count<-"0"
library(data.table)
library(expss)
setDT(dat)
dummy<-matrix(ncol=1,nrow=nrow(df2))
for (i in 1:nrow(df2)){
df_bounds<-data.frame(north=(df2[i,]$y.Lat+latint),south=(df2[i,]$y.Lat-latint),west=(df2[i,]$x.Lon-lonint),east=(df2[i,]$x.Lon+lonint))
dat[,inBounds := Lat >= (df2[i,]$y.Lat-latint) & Lat <= (df2[i,]$y.Lat+latint) & Lon >= (df2[i,]$x.Lon-lonint) & Lon >= (df2[i,]$x.Lon+lonint)]
dat1<-dat[SN %in% dat[inBounds == TRUE, unique(SN)],passesThroughBox := T]
#dat2<-dat[is.na(passesThroughBox),passesThroughBox := F]
#dat3<-dat1[which(passesThroughBox == TRUE),]
dummy[i,]<-count_if("TRUE",dat1$passesThroughBox)
}
PROBLEMS/QUESTIONS
The dummy matrix only contains 0 values.
I think I am not counting the unique points correctly.
EXPECTED OUTPUTS
The df2 data frame with an additional column containing the unique counts.
A gridded plot of df2, where the color corresponds to the counts.
Any suggestions on how to do this in R?
I'll appreciate any help.

Given the observations data-frame dat and grid data-frame df2. For each observation in dat find the nearest grid center in df2 to obtain the grid it belongs to.
This is based on assumption that an observation belongs to its nearest grid center. Also, For each SN only the first entry reported is taken as the unique observation.
df2<-as.data.frame(expand.grid(x.Lon=x.Lon,y.Lat=y.Lat)) # grid box centers
df2$count<- 0L # keeping count as integer
# function to calculate distance between two points
dist <- function(x, y) {diff <- (y - x) ; sqrt(sum(diff^2))}
# Filtering only the unique observation
dat <- dat[!duplicated(dat$SN), ]
# Finding closest grid center for every observation in dat
closest_grid <- apply(dat[,c('Lon','Lat')],1, function(x){
dist_grid <- apply(df2[,c('x.Lon','y.Lat')], 1, function(y) dist(x,y))
return(which.min(dist_grid))
})
# Summarizing no of of counts for each grid center with non zero counts
df2[names(table(closest_grid)),'count'] <- as.integer(table(closest_grid))
df2[names(table(closest_grid)),] # the non-zero counts
# x.Lon y.Lat count
#738 151.25 10.00 1
#1199 133.75 16.25 1
#1292 131.25 17.50 1
#1474 121.25 20.00 1
Use ggplot2 to plot the the count heat-map at grid centers:
library(ggplot2) # fill = counts data
ggplot(data = df2, aes(x = x.Lon, y = y.Lat)) + geom_tile(aes(fill = count))
The below plot is for your full data-set:

Related

geom_path with discrete boxplot data

Finally run out of ideas and links I could find to try and explain this so I need some help!
I'm trying to add a step-function to a ggplot chart using the cumSeg package. I did this successfully in this previous question, so I'm used to the usage of the function etc.
When I made the plot in that thread, it was fairly simple, just using an x vs y barplot for the mean values of x, and I added on error bars myself afterwards (thus it was a 16 x 2 dataframe).
I want to re-create this plot, but using sequential boxplots instead of bars, which I have done, using the raw data this time, which is ~250 observations in 16 factors (same factors as before).
Now when I try to add a geom_line,path or step it's complaining about the dimensions of the data not matching, because even though there are 16 factors/boxplots, there are now no longer 16 observations (Error: Aesthetics must be either length 1 or the same as the data (249): x, y, colour, group, fill)
To calculate the step function, I give it the means of each of the 16, which returns a 16-member vector, not ~250 (obviously).
How can I add the step function on to the box plot so that it understands it should pertain to the 16 factor values? I can't work out if it's a problem with the dataframe or how I'm giving it to ggplot.
I tried specifying it in a second dataframe, and passing it as geom_path(data=df2) instead of inheriting the main plots data, as in this question, but it still complains (Error: Aesthetics must be either length 1 or the same as the data (16): x, y, colour, group (the code below is in this form still)
data.melt <- melt(t(infile)
operon_gc <- 0.408891366
opgc_stdev <- 0.015712091
genome_gc <- 0.425031611
gengc_stdev <- 0.007587437
stepfunc <- jumpoints(y=aggregate(melted_data$value~melted_data$Var1, simplify=TRUE, FUN="mean")$`melted_data$value`, k=1, output="1")
func_data <- data.frame(x = c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16), y = stepfunc$fitted.values)
# Make boxplot
bp <- ggplot(melted_data, aes(x=Var1, y=value*100, fill=Var1)) + theme_bw()
#bp <- bp + scale_x_discrete(name = "Locus") + scale_y_continuous(name="GC Content (%)")
bp <- bp + geom_rect(xmin=0, xmax=17,
ymin=(operon_gc-opgc_stdev)*100,
ymax=(operon_gc+opgc_stdev)*100,
fill = "grey79", alpha=0.05)
bp <- bp + geom_rect(xmin=0, xmax=17,
ymin=(genome_gc-gengc_stdev)*100,
ymax=(genome_gc+gengc_stdev)*100,
fill = "beige", alpha=.08)
bp <- bp + geom_abline(intercept=genome_gc*100, slope=0,
colour="gray14", linetype=3)
bp <- bp + geom_abline(intercept=operon_gc*100, slope=0,
colour="gray14", linetype=3)
bp <- bp + geom_boxplot(alpha = 0.7)
bp <- bp + scale_color_manual(values = c("GC Step Fit"="red"), guides(color="Regression"))
bp <- bp + geom_path(linetype=4, size=0.9, aes(x=func_data$x,
y=func_data$y,
color="GC Step Fit",
group=1))
bp <- bp + theme(legend.position="bottom",
legend.direction="horizontal",
axis.text.x = element_text(angle=45, hjust=1)) + guides(fill=guide_legend(title="", nrow = 1))
bp
Data
> dput(func_data)
structure(list(x = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16), y = c(0.452456815737206, 0.452456815737206, 0.452456815737206,
0.452456815737206, 0.452456815737206, 0.452456815737206, 0.452456815737206,
0.452456815737206, 0.452456815737206, 0.452456815737206, 0.452456815737206,
0.375047391939972, 0.375047391939972, 0.375047391939972, 0.375047391939972,
0.375047391939972)), .Names = c("x", "y"), row.names = c(NA,
-16L), class = "data.frame")
> dput(melted_data)
structure(list(Var1 = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
16L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L, 15L, 16L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 11L, 12L, 13L, 14L, 15L, 16L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
16L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L, 15L, 16L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 1L, 2L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 14L, 15L, 16L, 1L, 2L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 15L, 16L, 1L, 2L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 15L, 16L, 11L), .Label = c("PVC1", "PVC2", "PVC3", "PVC4",
"PVC5", "PVC6", "PVC7", "PVC8", "PVC9", "PVC10", "PVC11", "PVC12",
"PVC13", "PVC14", "PVC15", "PVC16"), class = "factor"), Var2 = c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 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, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 17L
), value = c(0.404444444, 0.436329588, 0.46031746, 0.479318735,
0.466230937, 0.480874317, 0.476811594, 0.441558442, 0.449172577,
0.476525822, 0.452674897, 0.460918332, 0.368041912, 0.339160839,
0.415355269, 0.408163265, 0.401826484, 0.45411985, 0.468609865,
0.479735318, 0.464052288, 0.469945355, 0.476811594, 0.444032158,
0.453900709, 0.494004796, 0.467315716, 0.457805907, 0.387071651,
0.390737117, 0.408679065, 0.425170068, 0.355555556, 0.438069217,
0.423076923, 0.466666667, 0.450980392, 0.422222222, 0.469298246,
0.43196005, 0.416666667, 0.496402878, 0.428676201, 0.382113821,
0.349765258, 0.332280147, 0.373371925, 0.346448087, 0.415555556,
0.440508629, 0.435222672, 0.455833333, 0.446623094, 0.422222222,
0.463450292, 0.43258427, 0.425675676, 0.497584541, 0.422524565,
0.392592593, 0.362779741, 0.337552743, 0.379856115, 0.348888889,
0.391111111, 0.421004566, 0.426439232, 0.480367586, 0.472766885,
0.455555556, 0.495726496, 0.447565543, 0.424460432, 0.48441247,
0.435164835, 0.39600551, 0.3858393, 0.323655914, 0.383693046,
0.329988852, 0.395555556, 0.452380952, 0.454756381, 0.448129252,
0.496732026, 0.423728814, 0.502923977, 0.433832709, 0.41607565,
0.498800959, 0.399161736, 0.368421053, 0.386568387, 0.369901547,
0.398550725, 0.34006734, 0.406392694, 0.455840456, 0.458598726,
0.43792517, 0.501089325, 0.427777778, 0.49122807, 0.435081149,
0.416020672, 0.48441247, 0.40617284, 0.379298942, 0.402298851,
0.361462729, 0.396135266, 0.356666667, 0.353333333, 0.439182916,
0.469316597, 0.461868038, 0.490196078, 0.405555556, 0.505847953,
0.430529595, 0.406619385, 0.470023981, 0.395262768, 0.355072464,
0.373677249, 0.348008386, 0.382804995, 0.355481728, 0.415555556,
0.481481481, 0.4550036, 0.485074627, 0.501089325, 0.5, 0.51754386,
0.465043695, 0.438478747, 0.501199041, 0.457733481, 0.416815742,
0.360672976, 0.388285024, 0.397509579, 0.356589147, 0.384444444,
0.482917821, 0.452525253, 0.487864078, 0.501089325, 0.488888889,
0.513157895, 0.47627965, 0.475609756, 0.513189448, 0.471391657,
0.419797257, 0.38467433, 0.376081425, 0.396666667, 0.370985604,
0.42, 0.477777778, 0.436063218, 0.476782753, 0.490196078, 0.466666667,
0.51754386, 0.45505618, 0.44295302, 0.532374101, 0.460707635,
0.426019548, 0.35755814, 0.389842632, 0.388489209, 0.358730159,
0.422222222, 0.459610028, 0.473304473, 0.502487562, 0.509803922,
0.438888889, 0.516081871, 0.480024969, 0.457317073, 0.527577938,
0.460969293, 0.424148607, 0.386850153, 0.369161868, 0.397677794,
0.357696567, 0.433333333, 0.450704225, 0.429118774, 0.497031383,
0.505446623, 0.455555556, 0.492690058, 0.444444444, 0.409722222,
0.501199041, 0.444812362, 0.414860681, 0.361111111, 0.390096618,
0.394724221, 0.358803987, 0.426666667, 0.471837488, 0.495748299,
0.511982571, 0.45, 0.513157895, 0.465043695, 0.438478747, 0.498800959,
0.453200148, 0.409375, 0.329166667, 0.384172662, 0.38961039,
0.413333333, 0.406113537, 0.450728363, 0.435244161, 0.431693989,
0.441520468, 0.427745665, 0.378076063, 0.389671362, 0.427222222,
0.397905759, 0.423295455, 0.375268817, 0.391111111, 0.39893617,
0.461538462, 0.437367304, 0.448087432, 0.454678363, 0.421323057,
0.384787472, 0.394366197, 0.419141914, 0.401331931, 0.423768939,
0.368817204, 0.42680776)), .Names = c("Var1", "Var2", "value"
), row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L,
38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L,
51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L,
64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L,
77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L,
90L, 91L, 92L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L, 101L,
102L, 103L, 104L, 105L, 106L, 107L, 108L, 109L, 110L, 111L, 112L,
113L, 114L, 115L, 116L, 117L, 118L, 119L, 120L, 121L, 122L, 123L,
124L, 125L, 126L, 127L, 128L, 129L, 130L, 131L, 132L, 133L, 134L,
135L, 136L, 137L, 138L, 139L, 140L, 141L, 142L, 143L, 144L, 145L,
146L, 147L, 148L, 149L, 150L, 151L, 152L, 153L, 154L, 155L, 156L,
157L, 158L, 159L, 160L, 161L, 162L, 163L, 164L, 165L, 166L, 167L,
168L, 169L, 170L, 171L, 172L, 173L, 174L, 175L, 176L, 177L, 178L,
179L, 180L, 181L, 182L, 183L, 184L, 185L, 186L, 187L, 188L, 189L,
190L, 191L, 192L, 193L, 194L, 195L, 196L, 197L, 198L, 199L, 200L,
201L, 202L, 203L, 204L, 205L, 206L, 207L, 208L, 209L, 210L, 212L,
213L, 214L, 215L, 216L, 217L, 218L, 219L, 220L, 222L, 223L, 224L,
225L, 226L, 228L, 229L, 230L, 231L, 232L, 233L, 234L, 235L, 236L,
239L, 240L, 241L, 242L, 244L, 245L, 246L, 247L, 248L, 249L, 250L,
251L, 252L, 255L, 256L, 267L), class = "data.frame")
I'm not exactly sure how I solved this. I can only assume I was making a really stupid mistake before, but here's the code that finally produced the desired outcome:
bp_gc <- ggplot(melted_data, aes(x=Var1, y=value*100)) + theme_bw()
bp_gc <- bp_gc + geom_rect(xmin=0, xmax=17,
ymin=(operon_gc-opgc_stdev)*100,
ymax=(operon_gc+opgc_stdev)*100,
fill = "grey79", alpha=0.05)
bp_gc <- bp_gc + geom_rect(xmin=0, xmax=17,
ymin=(genome_gc-gengc_stdev)*100,
ymax=(genome_gc+gengc_stdev)*100,
fill = "beige", alpha=.08)
bp_gc <- bp_gc + geom_abline(intercept=genome_gc*100, slope=0,
colour="gray14", linetype=3)
bp_gc <- bp_gc + geom_abline(intercept=operon_gc*100, slope=0,
colour="gray14", linetype=3)
bp_gc <- bp_gc + geom_boxplot(alpha = 0.7, fill="dodgerblue", color="gray11")
bp_gc <- bp_gc + ylab("GC Content (%)")
bp_gc <- bp_gc + xlab("Locus")
bp_gc <- bp_gc + theme(legend.position = "none",
axis.text.x = element_text(angle=45, hjust=1))
bp_gc <- bp_gc + coord_cartesian(ylim=c(30,60))
bp_gc <- bp_gc + geom_path(data=func_data, linetype=4, size=0.9, aes(x=x,y=y*100))
bp_gc
I'm not 100% clear on what you're trying to achieve. Is it like this?
ggplot(melted_df, aes(Var1, value)) +
geom_boxplot()
ggplot(df, aes(Var1, value)) +
stat_summary(fun.y = median, geom = "path", aes(group = 1)) +
geom_boxplot()
If you really want to compute your statistics outside the main dataframe, it's usually best to do it something like this:
ggplot(df1, aes(x, y)) + geom_point() +
geom_path(data = summarydf, aes(xmean, ymean))

Error while storing ggplots in list. Impossible to plot multiple ggplot, but possible to plot them separately

I'm currently working on the effects of environmental variables on the toxicity of a shellfish. This toxicity happens only on certain years. I would like to compare time series of 15 different environmental variables between toxic years and non toxic years. My data or on 10 years and 6 locations.
I would like to have 1 window / site, each window containing 10 ggplots representing the 10 annual time series of one parameter
here are the data i give for a reproducible example, on one location, for one parameter (Temperature): (corrected to be reproducible)
structure(list(Date = structure(c(12065, 12065, 12079, 12079,
12088, 12095, 12095, 12104, 12115, 12115, 12123, 12123, 12130,
12130, 12135, 12137, 12137, 12142, 12146, 12146, 12149, 12150,
12150, 12156, 12157, 12157, 12164, 12164, 12165, 12170, 12177,
12177, 12177, 12184, 12185, 12185, 12191, 12192, 12192, 12198,
12199, 12199, 12205, 12206, 12206, 12213, 12215, 12215, 12219,
12219, 12219, 12226, 12233, 12235, 12235, 12240, 12240, 12240,
12240, 12240, 12240, 12248, 12248, 12248, 12254, 12255, 12255,
12261, 12263, 12263, 12268, 12268, 12268, 12275, 12275, 12275,
12282, 12283, 12283, 12289, 12291, 12291, 12296, 12297, 12297,
12303, 12305, 12305, 12311, 12311, 12318, 12318, 12326, 12331,
12338, 12352, 12368, 12381, 12395, 12403, 12424, 12436, 12452,
12464, 12478, 12495, 12507, 12522, 12528, 12534, 12541, 12548,
12562, 12571, 12571, 12576, 12576, 12583, 12583, 12591, 12598,
12613, 12620, 12625, 12633, 12639, 12646, 12653, 12661, 12667,
12676, 12682, 12690, 12696, 12702, 12709, 12716, 12724, 12730,
12744, 12758, 12772, 12795, 12800, 12814, 12828, 12843, 12856,
12871, 12877, 12884, 12898, 12905, 12912, 12926, 12933, 12940,
12954, 12954, 12961, 12961, 12968, 12968, 12982, 12982, 13011,
13011, 13024, 13024, 13038, 13052, 13052, 13067, 13083, 13094,
13111, 13122, 13136, 13151, 13166, 13178, 13192, 13206, 13221,
13236, 13248, 13262, 13270, 13278, 13292, 13298, 13305, 13318,
13318, 13326, 13332, 13332, 13333, 13339, 13346, 13346, 13377,
13390, 13402, 13432, 13466, 13529, 13542, 13585, 13599, 13614,
13626, 13643, 13655, 13669, 13675, 13683, 13698, 13710, 13725,
13731, 13741, 13754, 13760, 13767, 13781, 13789, 13795, 13809,
13823, 13838, 13851, 13867, 13901, 13901, 13907, 13921, 13936,
13936, 13957, 13963, 13963, 13978, 13992, 13992, 14005, 14020,
14020, 14036, 14036, 14041, 14047, 14047, 14047, 14047, 14047,
14053, 14054, 14061, 14061, 14069, 14076, 14076, 14076, 14076,
14077, 14082, 14089, 14089, 14105, 14105, 14105, 14105, 14118,
14118, 14131, 14131, 14145, 14145, 14152, 14160, 14166, 14173,
14180, 14188, 14202, 14216, 14230, 14258, 14271, 14287, 14299,
14312, 14327, 14340, 14354, 14368, 14375, 14382, 14397, 14411,
14411, 14425, 14425, 14440, 14440, 14447, 14453, 14453, 14467,
14467, 14474, 14481, 14481, 14488, 14494, 14502, 14509, 14509,
14516, 14523, 14539, 14565, 14579, 14593, 14607, 14635, 14649,
14663, 14683, 14700, 14706, 14714, 14719, 14727, 14736, 14749,
14763, 14763, 14777, 14777, 14791, 14819, 14819, 14824, 14832,
14832, 14845, 14845, 14861, 14861, 14873, 14873, 14888, 14902,
14929, 14985, 14999, 15015, 15029, 15043, 15057, 15071, 15085,
15097, 15111, 15125, 15141, 15141, 15153, 15153, 15167, 15167,
15181, 15181, 15195, 15195, 15209, 15209, 15223, 15237, 15237,
15251, 15265, 15281, 15293, 15307, 15321, 15335, 15349, 15377,
15391, 15405, 15419, 15433, 15447, 15457, 15463, 15474, 15491,
15503, 15503, 15517, 15517, 15523, 15533, 15545, 15545, 15559,
15559, 15573, 15573, 15589, 15589, 15601, 15601, 15615, 15629,
15643, 15657, 15671, 15685, 15702), class = "Date"), Annee = structure(c(9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L), .Label = c("1995", "1996", "1997", "1998", "1999", "2000",
"2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008",
"2009", "2010", "2011", "2012", "2013"), class = "factor"), Mois = structure(c(1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L,
11L, 11L, 12L, 12L, 1L, 1L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L,
5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 8L, 8L, 8L,
8L, 8L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 12L,
12L, 1L, 1L, 1L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 5L,
6L, 6L, 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9L, 9L, 10L, 10L, 10L, 11L, 11L, 12L, 12L), .Label = c("01",
"02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"
), class = "factor"), Jourannee = structure(c(12L, 12L, 26L,
26L, 35L, 42L, 42L, 51L, 62L, 62L, 70L, 70L, 77L, 77L, 82L, 84L,
84L, 89L, 93L, 93L, 96L, 97L, 97L, 103L, 104L, 104L, 111L, 111L,
112L, 117L, 124L, 124L, 124L, 131L, 132L, 132L, 138L, 139L, 139L,
145L, 146L, 146L, 152L, 153L, 153L, 160L, 162L, 162L, 166L, 166L,
166L, 173L, 180L, 182L, 182L, 187L, 187L, 187L, 187L, 187L, 187L,
195L, 195L, 195L, 201L, 202L, 202L, 208L, 210L, 210L, 215L, 215L,
215L, 222L, 222L, 222L, 229L, 230L, 230L, 236L, 238L, 238L, 243L,
244L, 244L, 250L, 252L, 252L, 258L, 258L, 265L, 265L, 273L, 278L,
285L, 299L, 314L, 327L, 341L, 349L, 6L, 18L, 34L, 46L, 60L, 77L,
89L, 104L, 110L, 116L, 123L, 130L, 144L, 153L, 153L, 158L, 158L,
165L, 165L, 173L, 180L, 195L, 202L, 207L, 215L, 221L, 228L, 235L,
243L, 249L, 258L, 264L, 272L, 278L, 284L, 291L, 298L, 306L, 312L,
325L, 339L, 353L, 11L, 16L, 30L, 44L, 59L, 72L, 87L, 93L, 100L,
114L, 121L, 128L, 142L, 149L, 156L, 170L, 170L, 177L, 177L, 184L,
184L, 198L, 198L, 227L, 227L, 240L, 240L, 254L, 268L, 268L, 283L,
299L, 310L, 326L, 337L, 351L, 2L, 17L, 29L, 43L, 57L, 72L, 87L,
99L, 113L, 121L, 129L, 143L, 149L, 156L, 169L, 169L, 177L, 183L,
183L, 184L, 190L, 197L, 197L, 228L, 241L, 253L, 283L, 316L, 15L,
28L, 71L, 85L, 100L, 112L, 129L, 141L, 155L, 161L, 169L, 184L,
196L, 211L, 217L, 227L, 240L, 246L, 253L, 267L, 275L, 281L, 295L,
309L, 323L, 336L, 352L, 22L, 22L, 28L, 42L, 57L, 57L, 78L, 84L,
84L, 99L, 113L, 113L, 126L, 141L, 141L, 157L, 157L, 162L, 168L,
168L, 168L, 168L, 168L, 174L, 175L, 182L, 182L, 190L, 197L, 197L,
197L, 197L, 198L, 203L, 210L, 210L, 226L, 226L, 226L, 226L, 239L,
239L, 252L, 252L, 266L, 266L, 273L, 281L, 287L, 294L, 301L, 309L,
322L, 336L, 350L, 13L, 26L, 42L, 54L, 67L, 82L, 95L, 109L, 123L,
130L, 137L, 152L, 166L, 166L, 180L, 180L, 195L, 195L, 202L, 208L,
208L, 222L, 222L, 229L, 236L, 236L, 243L, 249L, 257L, 264L, 264L,
271L, 278L, 294L, 319L, 333L, 347L, 360L, 25L, 39L, 53L, 73L,
90L, 96L, 104L, 109L, 117L, 126L, 139L, 153L, 153L, 167L, 167L,
181L, 209L, 209L, 214L, 222L, 222L, 235L, 235L, 251L, 251L, 263L,
263L, 278L, 292L, 318L, 10L, 24L, 40L, 54L, 68L, 82L, 96L, 110L,
122L, 136L, 150L, 166L, 166L, 178L, 178L, 192L, 192L, 206L, 206L,
220L, 220L, 234L, 234L, 248L, 262L, 262L, 276L, 290L, 306L, 317L,
331L, 345L, 358L, 9L, 37L, 51L, 65L, 79L, 93L, 107L, 117L, 123L,
134L, 151L, 163L, 163L, 177L, 177L, 183L, 193L, 205L, 205L, 219L,
219L, 233L, 233L, 249L, 249L, 261L, 261L, 275L, 289L, 303L, 316L,
330L, 344L, 360L), .Label = c("002", "003", "004", "005", "006",
"007", "008", "009", "010", "011", "012", "013", "014", "015",
"016", "017", "018", "019", "020", "021", "022", "023", "024",
"025", "026", "027", "028", "029", "030", "031", "032", "033",
"034", "035", "036", "037", "038", "039", "040", "041", "042",
"043", "044", "045", "046", "047", "048", "049", "050", "051",
"052", "053", "054", "055", "056", "057", "058", "059", "060",
"061", "062", "063", "064", "065", "066", "067", "068", "069",
"070", "071", "072", "073", "074", "075", "076", "077", "078",
"079", "080", "081", "082", "083", "084", "085", "086", "087",
"088", "089", "090", "091", "092", "093", "094", "095", "096",
"097", "098", "099", "100", "101", "102", "103", "104", "105",
"106", "107", "108", "109", "110", "111", "112", "113", "114",
"115", "116", "117", "118", "119", "120", "121", "122", "123",
"124", "125", "126", "127", "128", "129", "130", "131", "132",
"133", "134", "135", "136", "137", "138", "139", "140", "141",
"142", "143", "144", "145", "146", "147", "148", "149", "150",
"151", "152", "153", "154", "155", "156", "157", "158", "159",
"160", "161", "162", "163", "164", "165", "166", "167", "168",
"169", "170", "171", "172", "173", "174", "175", "176", "177",
"178", "179", "180", "181", "182", "183", "184", "185", "186",
"187", "188", "189", "190", "191", "192", "193", "194", "195",
"196", "197", "198", "199", "200", "201", "202", "203", "204",
"205", "206", "207", "208", "209", "210", "211", "212", "213",
"214", "215", "216", "217", "218", "219", "220", "221", "222",
"223", "224", "225", "226", "227", "228", "229", "230", "231",
"232", "233", "234", "235", "236", "237", "238", "239", "240",
"241", "242", "243", "244", "245", "246", "247", "248", "249",
"250", "251", "252", "253", "254", "255", "256", "257", "258",
"259", "260", "261", "262", "263", "264", "265", "266", "267",
"268", "269", "270", "271", "272", "273", "274", "275", "276",
"277", "278", "279", "280", "281", "282", "283", "284", "285",
"286", "287", "288", "289", "290", "291", "292", "293", "294",
"295", "296", "297", "298", "299", "300", "301", "302", "303",
"304", "305", "306", "307", "308", "309", "310", "311", "312",
"313", "314", "316", "317", "318", "319", "320", "321", "322",
"323", "324", "325", "326", "327", "328", "329", "330", "331",
"332", "333", "334", "335", "336", "337", "338", "339", "340",
"341", "342", "343", "344", "345", "346", "347", "348", "349",
"350", "351", "352", "353", "354", "355", "356", "357", "358",
"360", "361", "362", "363", "364", "365"), class = "factor"),
Mesure = c(8, 8, 9.5, 10, 9.5, 10.7, 10.7, 8.5, 9.8, 9.8,
10.3, 10.5, 10.4, 10.5, 11.7, 10.6, 10.6, 13.6, 11.1, 11.1,
11.4, 11, 11, 13, 11.3, 11.3, 12.8, 13.8, 14.4, 14.5, 13.5,
13.9, 15.1, 13.8, 12.5, 12.6, 13.4, 12.6, 12.6, 15, 14.1,
14.3, 17.1, 14.7, 14.9, 18.6, 19, 20, 18.8, 19.2, 19.3, 18.9,
17.7, 15.9, 16.2, 14.2, 14.7, 14.9, 15.3, 15.3, 16, 18.4,
18.4, 20, 20.4, 17.8, 17.8, 19.2, 17.5, 17.7, 17.6, 17.7,
21.3, 22.2, 22.2, 22.6, 20.9, 19.2, 20.2, 21.1, 19.7, 19.7,
18, 17.6, 18.9, 18.7, 16.9, 17.8, 17.2, 18.1, 17.6, 18.9,
17, 16.9, 15, 14.1, 13, 12.6, 11.7, 11, 10.7, 10.3, 10.4,
9.5, 8.2, 8.9, 10.1, 10.8, 10.9, 12.8, 13.1, 12.1, 14.8,
14.2, 17, 17.6, 17.8, 14.1, 17.7, 14.7, 14.7, 14.2, 15.3,
17.8, 18, 19.8, 18.3, 19.4, 16.9, 19, 17.6, 17.4, 16.4, 16.4,
15.8, 15.1, 14.8, 14.1, 14.2, 12.8, 12, 10.3, 10.7, 10.2,
9.7, 9.4, 7.7, 8, 11, 11.4, 10.7, 12, 13.1, 12.7, 14.3, 15.6,
14.7, 15, 18.5, 17.2, 19.3, 12.8, 15, 15, 17.7, 14.9, 17.3,
15.6, 16.6, 18.5, 16.4, 17.3, 16.4, 16.2, 15.1, 12.7, 10,
8.3, 7.3, 7, 8, 7.4, 7.4, 8.4, 9.2, 9.4, 12.7, 11.5, 14.2,
12.7, 12.5, 15.7, 17.8, 18.9, 17.4, 16.6, 18.7, 20.7, 20,
18, 18.9, 15.7, 16.1, 18.1, 17.6, 14.7, 12.1, 11, 11.8, 11,
12.4, 14.5, 12.7, 12.6, 14.4, 17.9, 16.6, 14.5, 16.2, 17.1,
18.7, 17.9, 17.4, 17.2, 18, 16.4, 14.4, 15.5, 14.2, 13.8,
12.1, 11.3, 8.9, 9.8, 9.8, 8.9, 8.4, 8.9, 8.9, 10.6, 10.2,
10.2, 10.8, 11.7, 11.7, 14, 16.2, 16.2, 14, 15, 15.6, 12.9,
12.9, 15, 15.7, 15.7, 16.6, 17.4, 12.9, 16.9, 15.5, 13.9,
13.9, 16.1, 16.1, 14.6, 14.1, 18, 18.6, 12.4, 12.4, 15.4,
15.4, 15.8, 17.2, 16.5, 16.5, 16.7, 16.8, 15.9, 14.3, 15.4,
15, 13.3, 13.2, 12.7, 11.4, 9.4, 6.9, 8.2, 8.4, 8.2, 9.5,
11.1, 11, 12.8, 12, 12.3, 13, 16.6, 13.5, 16.7, 14.2, 19.3,
13.7, 16.1, 14.2, 14.1, 17.2, 15, 17.3, 19.5, 16.2, 18.1,
17.4, 15.4, 16.9, 14.7, 16.6, 17.2, 16.6, 15.4, 11.8, 11.8,
10.2, 10, 7.1, 8.3, 8.2, 8, 9.8, 10.2, 12.1, 11.7, 13.4,
11.2, 13.1, 10.6, 13.2, 12.9, 14.6, 18, 12.7, 15.1, 16.3,
11.9, 15.7, 14.6, 17, 15.2, 17.5, 15, 16.3, 15.5, 15.7, 13,
7.7, 7.9, 8.4, 9.2, 8.7, 10, 12.1, 13.6, 15.3, 14.89, 13.05,
13.8, 14.89, 14.9, 16.41, 16.1, 16.39, 11.7, 14.8, 15.56,
16.72, 17, 18.07, 17.4, 15, 16.79, 18.27, 16.39, 15.6, 14.75,
13.87, 12.2, 11, 11.8, 9.71, 9.52, 10.47, 11.44, 12.05, 11.49,
11.6, 12.83, 14.05, 17.14, 12.6, 14.8, 12.6, 15.16, 16.1,
15.32, 16.8, 18.01, 15.5, 16.65, 18.8, 20.36, 16.8, 17.52,
15.6, 17.35, 15.8, 15.62, 14.86, 13.2, 12.11, 11.65, 12)), .Names = c("Date",
"Annee", "Mois", "Jourannee", "Mesure"), class = "data.frame", row.names = c("7413",
"7440", "16263", "19364", "16266", "22684", "22705", "9711",
"18115", "18133", "20630", "21431", "21054", "21437", "26379",
"22192", "22243", "34022", "24087", "24124", "25291", "23623",
"23663", "31760", "24950", "24959", "31098", "34997", "37850",
"38311", "33673", "35459", "40853", "34839", "29922", "30310",
"33231", "30314", "30326", "40496", "36427", "37419", "53855",
"39326", "40145", "64409", "69950", "81748", "66481", "72995",
"74404", "68002", "58822", "45098", "47124", "36883", "39239",
"40140", "41558", "41600", "45858", "63000", "63005", "81502",
"84446", "59280", "59288", "72676", "57414", "58961", "58115",
"58991", "89667", "91764", "91768", "92261", "87505", "72951",
"83212", "88778", "78851", "78893", "60137", "58123", "68201",
"65525", "52759", "59289", "55419", "61881", "58154", "68003",
"53356", "52695", "40657", "36449", "31885", "30332", "26459",
"23669", "22574", "20511", "20903", "16118", "8086", "12079",
"19751", "22853", "23163", "30939", "32157", "27887", "39661",
"36753", "53067", "57893", "59172", "36321", "58700", "39167",
"39170", "36734", "41402", "59170", "59903", "79538", "62765",
"75136", "52653", "69435", "57897", "56565", "48945", "48951",
"44503", "40840", "39670", "36315", "36742", "30945", "27506",
"20514", "22577", "20126", "17341", "15719", "6445", "7337",
"23464", "25247", "22580", "27509", "32163", "30559", "37312",
"43405", "39176", "40414", "63157", "54854", "74032", "30952",
"40404", "40417", "58699", "40005", "56083", "43409", "51235",
"63154", "49001", "56088", "48939", "46903", "40834", "30548",
"19184", "8756", "4488", "3263", "7334", "5070", "5079", "9252",
"14404", "15713", "30545", "25632", "36722", "30554", "29683",
"44042", "59178", "67753", "56643", "51255", "65461", "86321",
"81509", "59912", "67781", "44028", "46318", "61761", "57905",
"39173", "27890", "23455", "26624", "23461", "29204", "38270",
"30556", "30171", "37778", "59417", "51253", "38275", "46909",
"53720", "65458", "59418", "56588", "55061", "59906", "48962",
"37783", "42312", "36729", "34791", "27881", "24836", "12045",
"17979", "17984", "12054", "9250", "12064", "12072", "22002",
"20109", "20110", "22851", "26337", "26343", "35822", "46898",
"46901", "35832", "40398", "43545", "31363", "31366", "40409",
"44036", "44039", "51229", "56644", "31360", "52652", "42381",
"35285", "35288", "46301", "46304", "38784", "36367", "59915",
"64162", "29209", "29214", "41856", "41859", "44511", "54826",
"50116", "50123", "51750", "52291", "45044", "37307", "41911",
"40401", "32853", "32456", "30551", "25244", "15716", "3183",
"8084", "9255", "8088", "16121", "24000", "23451", "30942", "27499",
"28718", "31659", "51239", "33546", "51749", "36763", "74022",
"34331", "46314", "36739", "36327", "54836", "40426", "56091",
"76239", "46918", "61765", "56576", "41862", "52655", "39178",
"51245", "54846", "51252", "41865", "26627", "26633", "20111",
"19192", "3458", "8753", "8082", "7331", "18038", "20116", "27951",
"26348", "33149", "24365", "32151", "22014", "32459", "31371",
"38781", "59900", "30563", "40837", "47885", "27080", "44045",
"38786", "53065", "41042", "57129", "40420", "47846", "42315",
"44048", "31656", "6442", "7052", "9258", "14410", "10555", "19188",
"27884", "33979", "41399", "39928", "32069", "34796", "39931",
"40008", "49774", "46321", "48767", "26353", "39665", "43246",
"52091", "53071", "61427", "56562", "40428", "52180", "62728",
"48774", "43399", "39575", "35204", "28221", "23458", "26637",
"17853", "16513", "21209", "25556", "27842", "25597", "25991",
"31297", "36208", "54390", "30174", "39673", "30177", "41010",
"46309", "41781", "52294", "61206", "42318", "51654", "66398",
"84164", "52298", "57710", "43416", "56444", "44500", "43880",
"39901", "32468", "28144", "26261", "27515"))
here is an extract of my program
p<-list()
#Creating the graphs year by year
for(a in 1: 10){
#selecting the year
An<-baie[baie$Annee==unique(baie$Annee)[a],]
moyparam<-ddply(An, .(Date, Annee, Mois, Jourannee), function(x) data.frame(Mesure=mean(x$Mesure)))
p[[a]]<-ggplot(data=moyparam, aes(x=moyparam$Date, y=moyparam$Mesure))+geom_point()+theme_bw()
}
grid.arrange(p)
#or
multiplot(plotlist=p, layout=matrix(c(1:10),nrow=2,ncol=5, byrow=TRUE))
I manage to plot each graphs separately, they are even stored in a list, but when i display the list or when i try to do the multiple plot, i get a message:
Error in data.frame(x = c(15349, 15365, 15377, 15392, 15411, 15412,
15419, : arguments imply differing number of rows
Where am I wrong? Maybe the answer is simple, but i think i could use a new point of view on the problem.
Thank you for any help you can give me.
As an update:
thank you to Roland and noah for pointing my errors and helping me so quickly! but here's a precision:
I did not mention it previously, but my code is a bit more complicated than what is written here. In reality, i add a partially colored background on a "risk period" only on years where toxicity of the shelfish is observed (so that i can compare parameters on toxic years (precisely: on risk period) and non toxic years (on the entire year).
so my code is testing if the year is toxic, and if so, it add a color background on the risk period. I did not put it before because my error occurs even without this test, and i mention it now because it explains why i can't use facets grid (or can i? is there a way i can add partially colored background only on some facets?)
If you correct your misuse of $ in aes() the code works as expected,
p[[a]] <- ggplot(data=moyparam, aes(x=Date, y=Mesure)) +
geom_point()+theme_bw()
And here's a more concise way to do the processing:
baie2 = plyr::ddply(baie, .(Date, Annee, Mois, Jourannee),
summarise, Mesure = mean(Mesure))
base_plot = ggplot(baie2, aes(x=Date, y=Mesure)) + geom_point()+theme_bw()
lp = plyr::dlply(baie2, "Annee", `%+%`, e1 = base_plot)
from which you can arrange all plots in a page:
gridExtra::grid.arrange(grobs = lp)
Now, for the broader question, you have two options:
use facetting for the year, and a loop / **ply to open a new page for each site
base_plot + facet_wrap(~Annee, scales="free")
use gridExtra::marrangeGrob, like grid.arrange above but automatically splits the layout into multiple pages if necessary. It also works with ggsave.

Apply function to data grouped by cut()

I would like some help with summarising data using cut. I have been successful in less complicated situations, but now I am stuck.
The data:
> dput(sumsq)
structure(list(part_no = c(10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 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0.8, 0.8, 0.8, 0.8, 0, 0, 0, 0,
0, 0, 75.6, 0, 89.6, 24.8, -100, -100, 75.6, 100, 100, -100,
-100, -100, -100, -100, -100, 75.6, 98.4, 98.4, -51.2, -51.2,
0.8, 0.8, 0.4, 0.4, 0.4, 0.4, 75.2, -100, -100, -100, 1.2, -0.4,
-0.4, -0.4, -0.4, 100, 100, -1.6, 0, 0, 0, 0, -100, 0.4, 100,
0.4, 0.4, 100, -0.4, -78.4, 0.4, 100, 100, 100, 100, -100, 23.6,
61.2, 61.2, 69.2, 75.6, 75.6, 75.6, 75.6, 75.6, 98, 98, 98, -75.2,
-75.2, 47.2, 47.2, 47.2, 47.2, 76.8, 97.6, -71.6, -71.6, -71.6,
-71.6, 24, 52, 52, 52, 75.2, 75.2, -77.6, 25.2, 47.2, 76.4, 76.4,
76.4, 76.4, 76.4, 76.4, 76.4, 76.4, 76.4, 76.4, 76.4, 76.4, 76.4,
76.4, -73.2, -73.2, -73.2, -73.2, 0.8, 0.8, 75.2, 75.2, 75.2,
75.2, 75.2, 75.2, 0.4, 0.4, 0.4, 0.4, 0.4, -100, -100, -100,
-100, -100, 73.2, 2, -0.8, -0.8, -0.8, -100, -0.4, -0.4, 50.4,
50.4, 50.4, 50.4, 50.4, 50.4, -76.4, 99.6, 99.6, -76.4, 100,
100, 50.4, 1.2, 28, -1.2, 93.6, 41.2, 1.6, 24.8, -1.6, 0, 0,
24.8, -24, 26, 50.8, 2, 28, 36.4, 24, -43.6, 33.6, 61.2, 81.2,
86.8, 34, -51.6, -2, 28.4, 2, 82, 41.6, 25.6, 82, 0.8, 92, 1.2,
86.4, 54, 96, 0.4, -54.4, 1.2, -93.2, -49.2, -98.4, -2, -77.2,
93.2, 23.6, 78.8, 42.4, 0.4, 2.8, 70.8, 24.4, 2.4, 62, 92.8,
16.4, -61.2, 24.4, -77.2, -0.4, 74.8, 3.6, 82, 82, 18, 54, 9.2,
55.2, 96.4, 96.4, 90, 90, -84.4, -84.4, -2.8, -2, -90.4, 2.4,
34.8, 24, -1.6, -16.8, 2.8, 2.4, -83.2, 22.4, 22.4, -1.6, -1.6,
60, -2.4, 2.4, 2, 0.8, -22.8, 2, -1.6, 25.2, 2, 2, -52.8, -1.2,
-1.2, 3.2, -74.4, 3.2, 3.2, -78.4, 0.4, -2.4, 0.4, 0.4, 0.4,
0.4, 0.4, 0.4, -79.2, -0.8, -0.8, -0.8, -0.8, -0.8, -3.2, 41.2,
-0.8, -0.8, -0.8, -0.8, -83.2, -1.6, -1.6, 0.4, 0.4, 0.4, -90,
-1.6, -1.6, -1.6, -1.6, -1.6, -1.6, -1.6, -1.6, -1.6, -1.6, -1.6,
77.6, -79.6, 80.8, -81.6, -93.2, -100, 8.4, 75.6, 82.8, 67.2,
-27.2, 78.8, 65.6, 84.8, 73.6, 46.8, -62.4, 57.2, 74, 13.6, -0.8,
32.8, -27.2, 6.4, -67.2, 79.2, -64, 58, -40.4, 64, 8, 60, 76.8,
-24.8, -52.4, 56.8, 75.6, 38.4, -50.4, -72.8, -83.6, 24, 34.8,
54.4, -54, 67.6, 78.4, -41.6, -64.4, -83.6, -93.6, 76.8, -2.4,
-19.2, -54, -38, 5.2, 52.4, 64.8, 42.4, 77.6, -46.4, -74.8, -60.4,
-83.2, -56.4, -34.8, -16.8, 21.2, 40, 59.2, 0.4, -17.6, 24.4,
-14.4, 35.2, -26.8, 42, 44, -1.2, -35.6, 10.8, -19.6, -35.2,
22.4, -18.4, 27.6, -9.6, 43.2, -31.2, 45.2, 23.6, -16.4, 28.8,
40.4, 25.6, -8, 15.6, 11.2, -17.2, 15.6, -17.6, 18, 24, -9.6,
-34.8, 12.4, -17.2, 36.4, -9.2, -35.2, -19.6, 10.4, -15.6, -30.4,
30.8, 16.4, -14.8, -26.4, -34.4, 52.8, 34.4, 55.6, 21.2, 41.2,
52, 36.8, 50, 15.6, 36, 53.6, -22.8, 14.8, 25.2, -13.2, -18.8,
32, 20.8, -6.8, -16.4, -27.6, 14.4, 26.8, 38, -28.4, 19.6, -23.6,
18.4, -19.6, 11.6, 0, 0, 0, -26, -52.4, -24.4, 2, 19.6, -10.8,
3.6, 3.6, -25.2, 28.4, 12, -11.2, 3.2, 37.2, 26, 0.8, 47.6, -17.2,
2.4, -12, -52.4, 0.8, 28.4, -12, 36.4, 2.4, 50.4, -16, 24.4,
-2.4, -2.4, 15.2, -1.6, -1.6, -1.6, 24.4, -36, 33.2, 1.2, 1.2,
-48.8, -22.4, -1.2, -100, -1.6, -1.6, -26.4, 28, -47.6, 86, -1.6,
-1.6, -1.6, -1.6, -1.6, 41.6, -16, 29.6, -14.8, 3.2, 3.2, 100,
0.8, 0.8, 0.8, 0.8, 25.6, 24.8, -28, 0.8, -39.2, -97.6, -97.6,
-50, 0, 0, 49.6, 0.8, 54, 25.6, -1.2, -1.2, -90.8, 4.4, 4.4,
41.6, -40.8, -6, -6, 51.6, -8.4, 0, 0, 0, -60, 2.8, -52.4, 1.6,
1.6, 1.6, 18.8, 24.4, -0.4, -0.4, -0.4, -0.4, -51.6, -0.4, -0.4,
-0.4, 26, 0, 18, -42.4, -1.6, -0.4, 60.4, -2.8, -2.8, -2.8, 76,
2.8, 2.8, -29.2, -23.2, 23.6, -26.8, 0.4, 0.4, -40.8, -3.6, -47.6,
27.6, -2.4, -2.4, -76, -2, -2, -2, -30.8, 26.8, -4.4, -4.4, -4.4,
3.6, -0.8, -0.8, 67.2, -1.2, -48.8, 63.2, -42, 50, 30.8, 57.6,
-48.8, -48.8, 41.6, -39.2, -39.2, -35.6, 40, -44, -39.6, -39.6,
-50.8, 0, -48.8, 40, -53.2, 52, -47.2, -47.2, -46, 26.4, -29.2,
0, -46.8, -46.8, 34.8, -43.6, 0, 39.2, 0.4, -48.4, 0, -23.6,
29.2, 29.2, -53.2, -53.2, 19.2, 46.4, 46.4, -2, 36, 2, -25.2,
-50, -1.6, -2, 35.2, -32.8, 31.2, -43.2, 46, -28.8, -0.4, -50.4,
0.8, -43.6, 0.4, 27.6, -37.6, -37.6, 37.6, -50, 40.8, -0.8, -50.4,
-49.6, 45.6, 45.6, -48.8, -0.8, -54, -54, 43.2, -48.8, 46.4,
-42.8, 54, -54.4, 34.8, 0.4, 0.4, 0.4, 0.8, -50.4, -50.8, -50.8,
51.6, -68.8, 0.8, 52, -42, -42, 0, -56.8, -56.8, 0.8, -48, -46.4,
-46.8, -46.8, 0.4, 0.4, 37.2, -36.8, -36.8, -0.4, -0.4, -0.4,
-0.4, -0.4, -48.8, 0.8, 0.8, 58.8, 2, 2, 2, 2, 29.2, -50.4, 49.6,
41.2, -39.2, 38.8, -38.8, 28, -38, 40.8, 0.8, 0.8, 0.8, 0.8,
0.8, -51.2, 27.2, -54.8, 0.8, 0.8, -40.4, -40.4, 0, -46.8, 35.2,
-50.4, 9.6, -0.4, -15.2, 17.6, -26.8, -14.4, 42.8, 18.8, 2.8,
0, -33.2, -36.4, -7.6, 18.8, 34.4, 8.8, -25.6, -16.8, -10, -50.8,
10, -11.2, -7.2, -15.2, -62.8, 27.6, -12.8, -1.2, -24.4, 18.8,
-7.2, 37.2, 8.4, -40, -9.6, 20, -27.2, 27.2, 7.2, -31.6, -31.6,
27.6, -1.6, -20, -20, 34.4, 18, -23.6, 28.4, -16, 15.2, -30.4,
-9.2, -7.6, 12.4, 23.2, 15.6, 23.2, 37.2, -8.8, -21.6, -31.6,
-23.2, 25.2, 33.2, 9.2, 34.4, 18, 5.2, -50.4, 34.8, 12.4, -13.6,
-7.2, 6.4, 15.2, 2, 12.8, -14.4, 32.4, 15.6, 23.2, 30, -11.6,
-34.8, 12, -24, -11.2, -41.2, 34.4, 18.8, 18.8, 12, 37.6, 10,
35.2, -24.4, 24.8, 40.4, 52.4, 14, -41.6, 34, 43.2, -6, -28,
24, 35.2, 26.8, -15.2, 28, 38.8, 11.6, 57.6, 28, 12, -18.8, 35.6,
25.2, 40.4, 59.2, -58.4, 10.4, -23.6, 18, -14, 35.2, 13.6, 48.4,
32.8, 32.8, -17.2, -11.2, 26, -24, 15.2, -66.4, 24.4, -30.4,
39.6, 30, 53.2, 59.6, -40.4, -14, 36, 36, 41.6, 32, 57.6, 8.4,
62, 85.6, 85.6, 84.4, 38, 63.2, 67.2, -42.8, 63.6, 95.2, 65.2,
86.8, 87.2, 9.2, 83.2, 11.6, 83.2, 83.2, 79.6, 63.2, 88.8, -62,
-84.8, -84.8, -86.8, -4.4, 87.2, 86, 17.2, 81.6, -60.8, -87.6,
80, 37.2, -64.8, 86.4, 87.2, 94.4, 94, -61.6, 86.8, 86.4, 86.8,
86, -86, 94.4, -87.6, 80, 84.8, 86.8, -64.8, 85.2, 83.2, -90.8,
88.8, 85.6, 85.2, 87.2, 85.2, 85.6, -64, 84.8, 84.4, -90, 84.8,
82, -83.6, 88.4, 92, 80.8, 79.6, 80.4, 78.4, 78.4, 80, 80, 79.2,
81.2, 84.8, -78.4, 80.8, -88.8, 81.6, 81.6, -64.8, -85.6, 89.2,
90.4, -84, 85.2, -32.8, 49.6, 83.2, 81.2, 79.2, 80, 85.6, 81.6,
34.4, -85.6, 83.6, 82.4, 84, 81.2, 85.6, 85.6, 87.6, 84.8, 85.6,
82.8, -86.4, -60, 36.8, -85.6, 86.4, -65.6, 81.6, -81.2, 92.8,
-86.4, 84.8, 63.2, 36, 86.4, 86.4, 82.4, 83.2, 82.8, 82.4, 80.8,
80.4, 80.4, -63.6, 84.8, 84.8, 68, 93.2, 88, 89.6, 33.6, 83.6,
-67.2, 88.8, 88, 85.2, -39.6, 84.8), diffdist = c(-9L, -7L, -16L,
-17L, -38L, 55L, -17L, -2L, -18L, -24L, -7L, 24L, -40L, -35L,
69L, -42L, -15L, 80L, 73L, -28L, 39L, -46L, 40L, -49L, 11L, -9L,
-6L, -50L, 71L, 23L, -69L, -1L, 8L, 37L, -29L, -16L, 25L, -8L,
-44L, 27L, -20L, -11L, 16L, -16L, 40L, -57L, -13L, 13L, 40L,
-7L, 51L, -19L, -2L, -9L, 22L, 35L, -13L, -20L, -4L, -64L, 0L,
-48L, -55L, -19L, 20L, 6L, 31L, 9L, -62L, -4L, -50L, 39L, 53L,
-22L, 33L, 58L, 62L, -37L, 5L, -5L, 36L, 35L, -9L, 16L, -42L,
-20L, 7L, 24L, 29L, -80L, 41L, -18L, -28L, -16L, 6L, 15L, -37L,
52L, -12L, -40L, 64L, -28L, 22L, 29L, -4L, -47L, -3L, -61L, -2L,
21L, 3L, 9L, 35L, 73L, -20L, -8L, -53L, -19L, -11L, -6L, -56L,
17L, -20L, -66L, -16L, -29L, 26L, -29L, 44L, 38L, 40L, 51L, 84L,
-33L, -33L, -6L, -71L, -14L, -13L, -47L, 21L, 5L, -9L, -42L,
-26L, 35L, 53L, 2L, -6L, 31L, -22L, -70L, -17L, 35L, -55L, 9L,
-14L, 2L, 11L, -71L, 49L, 30L, -40L, -77L, 15L, 53L, -29L, 51L,
68L, -5L, -24L, -75L, -60L, -27L, -43L, -5L, -3L, -31L, -22L,
8L, -43L, 9L, -43L, -35L, 70L, -47L, -23L, 25L, -64L, 0L, -24L,
-17L, 68L, -12L, -57L, 28L, -9L, 42L, 35L, 21L, 13L, 9L, -9L,
-12L, 31L, -6L, -8L, -33L, 20L, -4L, -53L, 37L, -33L, 21L, 68L,
-28L, -56L, 61L, -69L, -12L, 9L, -23L, -60L, -9L, -7L, 45L, -44L,
-33L, 47L, -7L, 53L, -2L, -13L, -18L, 57L, -2L, 45L, 40L, -18L,
9L, -21L, 22L, 4L, 27L, 27L, -63L, -62L, -59L, 13L, -3L, -62L,
2L, 23L, 52L, 20L, -18L, 52L, 40L, -51L, -24L, -18L, -29L, -47L,
-33L, 64L, -74L, -36L, 18L, -36L, 22L, 8L, -46L, 24L, 4L, -74L,
-3L, 18L, -53L, 20L, 60L, -9L, -19L, 15L, 31L, 18L, 35L, 24L,
11L, -40L, -64L, 33L, -31L, 8L, 58L, 41L, -33L, -53L, -35L, 2L,
-19L, 42L, -53L, 64L, 46L, -53L, 62L, -77L, -18L, -3L, -11L,
33L, -67L, 68L, 0L, 51L, 13L, -11L, 40L, -65L, 22L, 39L, -5L,
76L, -44L, -35L, 15L, 0L, 13L, 7L, 6L, -51L, -44L, -20L, 20L,
11L, -55L, -66L, -49L, 4L, -58L, -27L, 20L, -16L, 42L, -69L,
71L, -68L, -42L, 44L, 31L, -13L, -63L, -72L, -13L, 19L, 39L,
-13L, 71L, -53L, -33L, 67L, -42L, 14L, 39L, 33L, -13L, -19L,
73L, -71L, -24L, 11L, 0L, -42L, -71L, -1L, -62L, -11L, -7L, 18L,
49L, 8L, -21L, -5L, 13L, -38L, 62L, -15L, -27L, 0L, -33L, 9L,
-40L, -57L, 60L, 73L, -24L, 0L, 22L, -37L, -46L, -27L, 27L, 0L,
6L, 77L, -13L, 47L, 71L, -20L, 11L, 18L, 31L, 8L, 80L, -87L,
-20L, 57L, -37L, 24L, 62L, -11L, -50L, 9L, 52L, 7L, 2L, -57L,
-50L, 69L, 7L, -42L, -43L, -22L, 46L, 57L, 24L, 35L, 9L, -54L,
51L, 6L, -8L, -8L, 9L, 48L, 24L, 31L, -55L, 53L, 44L, 7L, -7L,
22L, -53L, 42L, -44L, -2L, 6L, -9L, -5L, 33L, -20L, 20L, 36L,
39L, -16L, -25L, 44L, -28L, 4L, -4L, -47L, -87L, 6L, -38L, 51L,
-9L, 37L, -47L, 72L, -19L, 26L, 37L, -43L, 29L, -11L, 54L, 4L,
-41L, -24L, -55L, 11L, 35L, 22L, 57L, 61L, 40L, -52L, -17L, 10L,
28L, -24L, -28L, -3L, -9L, -47L, 40L, 35L, 57L, 13L, 13L, 33L,
24L, 22L, -67L, -49L, -77L, 7L, -36L, 9L, 29L, -16L, -5L, 11L,
-13L, 57L, -17L, 49L, 66L, -55L, -33L, -6L, -29L, 5L, -62L, 80L,
33L, 73L, 87L, -3L, 18L, 40L, 18L, 70L, 49L, 55L, 5L, -13L, 9L,
-17L, 36L, -22L, 9L, 0L, -75L, -40L, -12L, 17L, 19L, -9L, 13L,
-15L, -51L, 10L, -20L, 1L, 3L, 40L, 38L, 19L, 11L, 0L, 89L, -10L,
49L, 44L, 75L, 83L, -8L, 36L, -60L, 38L, -53L, -19L, 11L, 4L,
-53L, -51L, -11L, 71L, 20L, 7L, -33L, 37L, 3L, 49L, 22L, -57L,
-74L, -30L, 22L, 11L, -9L, -19L, -51L, -42L, 3L, 55L, -42L, -7L,
-19L, -53L, 32L, -73L, 11L, -9L, -31L, 20L, -5L, 55L, -26L, -22L,
-28L, 75L, -15L, -58L, 20L, 37L, -26L, -57L, -50L, -47L, -35L,
-20L, 22L, 1L, 28L, 0L, -38L, 24L, 40L, 22L, -33L, 34L, -28L,
-18L, 33L, -57L, 4L, -13L, -25L, -62L, 33L, -62L, 55L, 28L, -9L,
14L, -50L, -18L, -40L, 20L, 24L, -53L, -27L, 23L, 4L, 13L, 27L,
-55L, -4L, 44L, 4L, -9L, -17L, -44L, -42L, 18L, -33L, -44L, 17L,
-53L, -13L, -24L, -56L, -41L, 28L, 31L, 21L, -13L, 27L, -46L,
-50L, -25L, 29L, -7L, -6L, -11L, -18L, 71L, -69L, -50L, -3L,
2L, 18L, -24L, -40L, -15L, -46L, 11L, 29L, 10L, -30L, 7L, -13L,
50L, 77L, 2L, 9L, -71L, -9L, -62L, -55L, 29L, 38L, -48L, -22L,
-30L, 39L, -44L, 42L, -5L, -61L, 16L, 24L, -46L, 2L, 4L, -8L,
-16L, 33L, -35L, 80L, -39L, 19L, -55L, -23L, -46L, 2L, 7L, -77L,
-5L, 18L, -44L, -18L, -62L, -62L, -84L, 85L, 13L, 49L, 11L, 41L,
40L, -38L, 15L, 39L, -13L, 39L, -11L, -64L, 58L, 35L, -18L, 34L,
18L, 24L, -22L, -4L, -46L, -71L, 22L, -44L, -49L, -11L, -40L,
-4L, 11L, -5L, 37L, -24L, -27L, -33L, 52L, -11L, 9L, -54L, 0L,
-24L, 0L, 18L, 13L, -17L, 22L, 64L, 58L, 71L, -6L, -24L, 29L,
-3L, -22L, -9L, 55L, -9L, -16L, -35L, 56L, 25L, -58L, -26L, -9L,
62L, -48L, -62L, 9L, 35L, -8L, 33L, 40L, 55L, 40L, 35L, -23L,
11L, 46L, 62L, -15L, -2L, -9L, -17L, 39L, 15L, -13L, -37L, 20L,
-7L, -14L, 70L, 28L, -2L, 55L, -25L, 6L, -36L, 30L, 62L, 66L,
11L, 24L, -42L, 58L, 9L, 45L, 4L, 0L, -20L, 20L, 27L, -4L, 3L,
-40L, -2L, 2L, 10L, 8L, 20L, -24L, -39L, -13L, 20L, -45L, -76L,
-46L, 3L, -55L, -18L, 22L, 2L, -14L, -20L, -26L, 51L, -66L, -9L,
0L, 51L, 22L, -12L, 27L, -35L, 11L, 38L, -3L, 15L, 4L, -55L,
44L, -55L, -46L, 6L, -46L, 22L, 22L, 46L, 20L, 35L, -11L, -20L,
-53L, 51L, -80L, -59L, -53L, -78L, -36L, -13L, 31L, 33L, -9L,
-26L, 31L, -14L, -16L, -15L, -53L, 9L, 65L, 3L, 44L, -42L, 45L,
-13L, -7L, -6L, 52L, 60L, -3L, -3L, 7L, -40L, 2L, 29L, 11L, 33L,
40L, -16L, -9L, -21L, 78L, -60L, 15L, 0L, 17L, -15L, -18L, 48L,
26L, 31L, -53L, -9L, -3L, -1L, 64L, 7L, 44L, -38L, -23L, 13L,
55L, 57L, -71L, -20L, 23L, -18L, 4L, 16L, -7L, 52L, 42L, 24L,
5L, -2L, 6L, -33L, 9L, 30L, -51L, 58L, 53L, -44L, -22L, -44L,
-75L, -60L, 46L, 14L, 13L, -5L, -7L, 69L, -18L, 53L, 52L, -62L,
-13L, 22L, 64L, -18L, 71L, 24L, -9L, 68L, -40L, -10L, -2L, 12L,
37L, 40L, 79L, 3L, 42L, -55L, 7L, -31L, 20L, 16L, 7L, 11L, -14L,
70L, 24L, 3L, -57L, -14L, 51L, -19L, -62L, -16L, -2L, -68L, 4L,
7L, -20L, 4L, -15L, 49L, -16L, 11L, 6L, 56L, -6L, 68L, 28L, 33L,
-62L, 20L, -39L, -12L, -45L, -30L, -15L, 37L, 44L, 39L, 38L,
46L, 33L, 2L, -3L, 29L, 44L, 2L, -57L, 37L, 42L, 20L, 5L, 53L,
-51L, 11L, -5L, -24L, 7L, 29L, -20L, -15L, 24L, 80L, 4L, 82L,
29L, -24L, 68L, -38L, 27L, 71L, 30L, 42L, 14L, -75L, -41L, 22L,
46L, -72L, -53L, 78L, 54L, 22L, -55L, 57L, -1L, -54L, 80L, 68L,
-17L, -18L, -3L, 5L, 16L, -39L, -21L, -29L, -64L, -5L, 46L, -8L,
3L, -15L, 26L, -6L, 38L, -2L, -13L, -62L, -51L, -60L, 9L, -64L,
51L, 31L, 36L, 0L, -35L, 29L, 22L, 31L, -2L, 14L, 73L, -17L,
17L, -58L, 55L, 37L, -16L, 71L, 28L, 72L, -26L, 22L, 12L, 25L,
23L, -46L, -9L, -55L, -7L, 18L, -40L, 28L, -9L, 5L, -6L, 26L,
58L, 31L, -38L, -27L, 14L, -34L, -5L, 9L, 20L, -35L, 31L, -3L,
-19L, -33L, 34L)), .Names = c("part_no", "ratperc", "diffdist"
), row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L,
38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L,
51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L,
64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L,
77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L,
90L, 91L, 92L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L, 101L,
102L, 103L, 104L, 105L, 106L, 107L, 108L, 109L, 110L, 111L, 112L,
113L, 114L, 115L, 116L, 117L, 118L, 119L, 120L, 121L, 122L, 123L,
124L, 125L, 126L, 127L, 128L, 129L, 130L, 131L, 132L, 133L, 134L,
135L, 136L, 137L, 138L, 139L, 140L, 141L, 142L, 143L, 144L, 145L,
146L, 147L, 148L, 149L, 150L, 301L, 302L, 303L, 304L, 305L, 306L,
307L, 308L, 309L, 310L, 311L, 312L, 313L, 314L, 315L, 316L, 317L,
318L, 319L, 320L, 321L, 322L, 323L, 324L, 325L, 326L, 327L, 328L,
329L, 330L, 331L, 332L, 333L, 334L, 335L, 336L, 337L, 338L, 339L,
340L, 341L, 342L, 343L, 344L, 345L, 346L, 347L, 348L, 349L, 350L,
351L, 352L, 353L, 354L, 355L, 356L, 357L, 358L, 359L, 360L, 361L,
362L, 363L, 364L, 365L, 366L, 367L, 368L, 369L, 370L, 371L, 372L,
373L, 374L, 375L, 376L, 377L, 378L, 379L, 380L, 381L, 382L, 383L,
384L, 385L, 386L, 387L, 388L, 389L, 390L, 391L, 392L, 393L, 394L,
395L, 396L, 397L, 398L, 399L, 400L, 401L, 402L, 403L, 404L, 405L,
406L, 407L, 408L, 409L, 410L, 411L, 412L, 413L, 414L, 415L, 416L,
417L, 418L, 419L, 420L, 421L, 422L, 423L, 424L, 425L, 426L, 427L,
428L, 429L, 430L, 431L, 432L, 433L, 434L, 435L, 436L, 437L, 438L,
439L, 440L, 441L, 442L, 443L, 444L, 445L, 446L, 447L, 448L, 449L,
450L, 601L, 602L, 603L, 604L, 605L, 606L, 607L, 608L, 609L, 610L,
611L, 612L, 613L, 614L, 615L, 616L, 617L, 618L, 619L, 620L, 621L,
622L, 623L, 624L, 625L, 626L, 627L, 628L, 629L, 630L, 631L, 632L,
633L, 634L, 635L, 636L, 637L, 638L, 639L, 640L, 641L, 642L, 643L,
644L, 645L, 646L, 647L, 648L, 649L, 650L, 651L, 652L, 653L, 654L,
655L, 656L, 657L, 658L, 659L, 660L, 661L, 662L, 663L, 664L, 665L,
666L, 667L, 668L, 669L, 670L, 671L, 672L, 673L, 674L, 675L, 676L,
677L, 678L, 679L, 680L, 681L, 682L, 683L, 684L, 685L, 686L, 687L,
688L, 689L, 690L, 691L, 692L, 693L, 694L, 695L, 696L, 697L, 698L,
699L, 700L, 701L, 702L, 703L, 704L, 705L, 706L, 707L, 708L, 709L,
710L, 711L, 712L, 713L, 714L, 715L, 716L, 717L, 718L, 719L, 720L,
721L, 722L, 723L, 724L, 725L, 726L, 727L, 728L, 729L, 730L, 731L,
732L, 733L, 734L, 735L, 736L, 737L, 738L, 739L, 740L, 741L, 742L,
743L, 744L, 745L, 746L, 747L, 748L, 749L, 750L, 901L, 902L, 903L,
904L, 905L, 906L, 907L, 908L, 909L, 910L, 911L, 912L, 913L, 914L,
915L, 916L, 917L, 918L, 919L, 920L, 921L, 922L, 923L, 924L, 925L,
926L, 927L, 928L, 929L, 930L, 931L, 932L, 933L, 934L, 935L, 936L,
937L, 938L, 939L, 940L, 941L, 942L, 943L, 944L, 945L, 946L, 947L,
948L, 949L, 950L, 951L, 952L, 953L, 954L, 955L, 956L, 957L, 958L,
959L, 960L, 961L, 962L, 963L, 964L, 965L, 966L, 967L, 968L, 969L,
970L, 971L, 972L, 973L, 974L, 975L, 976L, 977L, 978L, 979L, 980L,
981L, 982L, 983L, 984L, 985L, 986L, 987L, 988L, 989L, 990L, 991L,
992L, 993L, 994L, 995L, 996L, 997L, 998L, 999L, 1000L, 1001L,
1002L, 1003L, 1004L, 1005L, 1006L, 1007L, 1008L, 1009L, 1010L,
1011L, 1012L, 1013L, 1014L, 1015L, 1016L, 1017L, 1018L, 1019L,
1020L, 1021L, 1022L, 1023L, 1024L, 1025L, 1026L, 1027L, 1028L,
1029L, 1030L, 1031L, 1032L, 1033L, 1034L, 1035L, 1036L, 1037L,
1038L, 1039L, 1040L, 1041L, 1042L, 1043L, 1044L, 1045L, 1046L,
1047L, 1048L, 1049L, 1050L, 1201L, 1202L, 1203L, 1204L, 1205L,
1206L, 1207L, 1208L, 1209L, 1210L, 1211L, 1212L, 1213L, 1214L,
1215L, 1216L, 1217L, 1218L, 1219L, 1220L, 1221L, 1222L, 1223L,
1224L, 1225L, 1226L, 1227L, 1228L, 1229L, 1230L, 1231L, 1232L,
1233L, 1234L, 1235L, 1236L, 1237L, 1238L, 1239L, 1240L, 1241L,
1242L, 1243L, 1244L, 1245L, 1246L, 1247L, 1248L, 1249L, 1250L,
1251L, 1252L, 1253L, 1254L, 1255L, 1256L, 1257L, 1258L, 1259L,
1260L, 1261L, 1262L, 1263L, 1264L, 1265L, 1266L, 1267L, 1268L,
1269L, 1270L, 1271L, 1272L, 1273L, 1274L, 1275L, 1276L, 1277L,
1278L, 1279L, 1280L, 1281L, 1282L, 1283L, 1284L, 1285L, 1286L,
1287L, 1288L, 1289L, 1290L, 1291L, 1292L, 1293L, 1294L, 1295L,
1296L, 1297L, 1298L, 1299L, 1300L, 1301L, 1302L, 1303L, 1304L,
1305L, 1306L, 1307L, 1308L, 1309L, 1310L, 1311L, 1312L, 1313L,
1314L, 1315L, 1316L, 1317L, 1318L, 1319L, 1320L, 1321L, 1322L,
1323L, 1324L, 1325L, 1326L, 1327L, 1328L, 1329L, 1330L, 1331L,
1332L, 1333L, 1334L, 1335L, 1336L, 1337L, 1338L, 1339L, 1340L,
1341L, 1342L, 1343L, 1344L, 1345L, 1346L, 1347L, 1348L, 1349L,
1350L, 1501L, 1502L, 1503L, 1504L, 1505L, 1506L, 1507L, 1508L,
1509L, 1510L, 1511L, 1512L, 1513L, 1514L, 1515L, 1516L, 1517L,
1518L, 1519L, 1520L, 1521L, 1522L, 1523L, 1524L, 1525L, 1526L,
1527L, 1528L, 1529L, 1530L, 1531L, 1532L, 1533L, 1534L, 1535L,
1536L, 1537L, 1538L, 1539L, 1540L, 1541L, 1542L, 1543L, 1544L,
1545L, 1546L, 1547L, 1548L, 1549L, 1550L, 1551L, 1552L, 1553L,
1554L, 1555L, 1556L, 1557L, 1558L, 1559L, 1560L, 1561L, 1562L,
1563L, 1564L, 1565L, 1566L, 1567L, 1568L, 1569L, 1570L, 1571L,
1572L, 1573L, 1574L, 1575L, 1576L, 1577L, 1578L, 1579L, 1580L,
1581L, 1582L, 1583L, 1584L, 1585L, 1586L, 1587L, 1588L, 1589L,
1590L, 1591L, 1592L, 1593L, 1594L, 1595L, 1596L, 1597L, 1598L,
1599L, 1600L, 1601L, 1602L, 1603L, 1604L, 1605L, 1606L, 1607L,
1608L, 1609L, 1610L, 1611L, 1612L, 1613L, 1614L, 1615L, 1616L,
1617L, 1618L, 1619L, 1620L, 1621L, 1622L, 1623L, 1624L, 1625L,
1626L, 1627L, 1628L, 1629L, 1630L, 1631L, 1632L, 1633L, 1634L,
1635L, 1636L, 1637L, 1638L, 1639L, 1640L, 1641L, 1642L, 1643L,
1644L, 1645L, 1646L, 1647L, 1648L, 1649L, 1650L, 1801L, 1802L,
1803L, 1804L, 1805L, 1806L, 1807L, 1808L, 1809L, 1810L, 1811L,
1812L, 1813L, 1814L, 1815L, 1816L, 1817L, 1818L, 1819L, 1820L,
1821L, 1822L, 1823L, 1824L, 1825L, 1826L, 1827L, 1828L, 1829L,
1830L, 1831L, 1832L, 1833L, 1834L, 1835L, 1836L, 1837L, 1838L,
1839L, 1840L, 1841L, 1842L, 1843L, 1844L, 1845L, 1846L, 1847L,
1848L, 1849L, 1850L, 1851L, 1852L, 1853L, 1854L, 1855L, 1856L,
1857L, 1858L, 1859L, 1860L, 1861L, 1862L, 1863L, 1864L, 1865L,
1866L, 1867L, 1868L, 1869L, 1870L, 1871L, 1872L, 1873L, 1874L,
1875L, 1876L, 1877L, 1878L, 1879L, 1880L, 1881L, 1882L, 1883L,
1884L, 1885L, 1886L, 1887L, 1888L, 1889L, 1890L, 1891L, 1892L,
1893L, 1894L, 1895L, 1896L, 1897L, 1898L, 1899L, 1900L, 1901L,
1902L, 1903L, 1904L, 1905L, 1906L, 1907L, 1908L, 1909L, 1910L,
1911L, 1912L, 1913L, 1914L, 1915L, 1916L, 1917L, 1918L, 1919L,
1920L, 1921L, 1922L, 1923L, 1924L, 1925L, 1926L, 1927L, 1928L,
1929L, 1930L, 1931L, 1932L, 1933L, 1934L, 1935L, 1936L, 1937L,
1938L, 1939L, 1940L, 1941L, 1942L, 1943L, 1944L, 1945L, 1946L,
1947L, 1948L, 1949L, 1950L, 2101L, 2102L, 2103L, 2104L, 2105L,
2106L, 2107L, 2108L, 2109L, 2110L, 2111L, 2112L, 2113L, 2114L,
2115L, 2116L, 2117L, 2118L, 2119L, 2120L, 2121L, 2122L, 2123L,
2124L, 2125L, 2126L, 2127L, 2128L, 2129L, 2130L, 2131L, 2132L,
2133L, 2134L, 2135L, 2136L, 2137L, 2138L, 2139L, 2140L, 2141L,
2142L, 2143L, 2144L, 2145L, 2146L, 2147L, 2148L, 2149L, 2150L,
2151L, 2152L, 2153L, 2154L, 2155L, 2156L, 2157L, 2158L, 2159L,
2160L, 2161L, 2162L, 2163L, 2164L, 2165L, 2166L, 2167L, 2168L,
2169L, 2170L, 2171L, 2172L, 2173L, 2174L, 2175L, 2176L, 2177L,
2178L, 2179L, 2180L, 2181L, 2182L, 2183L, 2184L, 2185L, 2186L,
2187L, 2188L, 2189L, 2190L, 2191L, 2192L, 2193L, 2194L, 2195L,
2196L, 2197L, 2198L, 2199L, 2200L, 2201L, 2202L, 2203L, 2204L,
2205L, 2206L, 2207L, 2208L, 2209L, 2210L, 2211L, 2212L, 2213L,
2214L, 2215L, 2216L, 2217L, 2218L, 2219L, 2220L, 2221L, 2222L,
2223L, 2224L, 2225L, 2226L, 2227L, 2228L, 2229L, 2230L, 2231L,
2232L, 2233L, 2234L, 2235L, 2236L, 2237L, 2238L, 2239L, 2240L,
2241L, 2242L, 2243L, 2244L, 2245L, 2246L, 2247L, 2248L, 2249L,
2250L), class = "data.frame")
using the vector:
timevec1 = as.vector(ggplot2:::breaks(sumsq$diffdist, "n", n=8))
I normally summarise the data using xtabs and cutusing:
bb1 = data.frame(xtabs(~ratperc +cut(diffdist, timevec1 ), dat=sumsq))
colnames(bb1) = c("rating", "range", "freq", "id")
While this solution is not idea for what I wanted it, I was able to then summarise the values for each cut using ddply.
However now I need to preserve the part_no too, but I can't seem to be able to pass more than one column to cut.
The question is, is there any way to do everything in one step? Basically get for each participant the mean of all the ratings for each cut? In other words, part_no as rows, ranges as columns and the intersection being the mean of ratings for the values that below there.
If you just want the mean rating for each part_no and interval from cut(diffdist, timevec1 ) I would just do something like this:
#Add cut variable as new column
sumsq$range <- cut(sumsq$diffdist,timevec1)
#Summarise using ddply
ddply(sumsq,.(part_no,range),summarise,val = mean(ratperc))
I didn't get if you want the mean for each participant and interval or the cumulative mean along the intervals for each participant.
If you want the normal mean you can get it with
sapply(split(sumsq, cut(sumsq$diffdist, timevec1)), function(ss)
sapply(split(ss$ratperc, ss$part_no), mean))
If you want the cumulative you can rephrase it as
t(sapply(split(sumsq, sumsq$part_no), function(ss){
sapply(timevec1[-1], function(tc) mean(ss$ratperc[ss$diffdist <= tc]))
}))

Plot dates on the x axis and time on the y axis with ggplot2

I have read in a series of 37 dates and times that an event happened. It is now sitting as a POSIXlt object. I want a graphic representation of the times that the events happened on each day. So the x axis should be the date and y axis should be the time of day.
then I tried to plot it with ggplot2
qplot(day(dttm), hour(dttm))
That is kind of what I want but it does not have the resolution of minutes. How do I have hours and minutes included in the y axis?
Here is some sample data
dttm
[1] "2011-11-16 10:39:20" "2011-11-16 10:56:32" "2011-11-16 11:52:43" "2011-11-16 12:10:42"
[5] "2011-11-16 13:10:13" "2011-11-16 13:41:10" "2011-11-16 13:48:07" "2011-11-16 14:54:04"
[9] "2011-11-17 07:05:23" "2011-11-17 07:34:24" "2011-11-17 07:53:01" "2011-11-17 07:57:04"
[13] "2011-11-17 08:09:16" "2011-11-17 08:23:43" "2011-11-17 10:20:54" "2011-11-17 10:45:13"
[17] "2011-11-17 10:49:32" "2011-11-17 11:16:08" "2011-11-17 11:24:05" "2011-11-17 11:50:11"
[21] "2011-11-17 11:52:47" "2011-11-17 11:54:42" "2011-11-17 11:55:25" "2011-11-17 11:57:34"
[25] "2011-11-17 12:06:15" "2011-11-17 12:08:05" "2011-11-17 12:08:33" "2011-11-17 12:30:13"
[29] "2011-11-17 13:24:41" "2011-11-17 13:44:41" "2011-11-17 13:48:55" "2011-11-17 14:59:08"
[33] "2011-11-18 06:46:17" "2011-11-18 07:52:50" "2011-11-18 08:31:22" "2011-11-18 08:33:43"
[37] "2011-11-18 08:50:08"
Here is the dput file
structure(list(sec = c(20, 32, 43, 42, 13, 10, 7, 4, 23, 24,
1, 4, 16, 43, 54, 13, 32, 8, 5, 11, 47, 42, 25, 34, 15, 5, 33,
13, 41, 41, 55, 8, 17, 50, 22, 43, 8), min = c(39L, 56L, 52L,
10L, 10L, 41L, 48L, 54L, 5L, 34L, 53L, 57L, 9L, 23L, 20L, 45L,
49L, 16L, 24L, 50L, 52L, 54L, 55L, 57L, 6L, 8L, 8L, 30L, 24L,
44L, 48L, 59L, 46L, 52L, 31L, 33L, 50L), hour = c(10L, 10L, 11L,
12L, 13L, 13L, 13L, 14L, 7L, 7L, 7L, 7L, 8L, 8L, 10L, 10L, 10L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 13L, 13L,
13L, 14L, 6L, 7L, 8L, 8L, 8L), mday = c(16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 18L, 18L, 18L, 18L, 18L), mon = c(10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L), year = c(111L, 111L, 111L, 111L,
111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L,
111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L,
111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L
), wday = c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L), yday = c(319L, 319L, 319L, 319L,
319L, 319L, 319L, 319L, 320L, 320L, 320L, 320L, 320L, 320L, 320L,
320L, 320L, 320L, 320L, 320L, 320L, 320L, 320L, 320L, 320L, 320L,
320L, 320L, 320L, 320L, 320L, 320L, 321L, 321L, 321L, 321L, 321L
), isdst = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L)), .Names = c("sec", "min",
"hour", "mday", "mon", "year", "wday", "yday", "isdst"), class = c("POSIXlt",
"POSIXt"))
There are two steps required:
Extract the time element from the POSIXct object. You can do that with some lubridate extractor functions and a bit of arithmetic, or by subtracting as.Date(dttm) from dttm. I show both ways.
Add a date-time y-axis and specify a suitable formatter
Two alternative ways to extract the time from a POSIXct object:
dropDate <- function(x){
3600*hour(x)+60*minute(x)+second(x)
}
dropDate2 <- function(x){
as.numeric(x - as.Date(x))
}
You may also wish to specify explicit labels for the axes:
qplot(day(dttm), dropDate(dttm)) +
scale_y_datetime(format="%H:%M:%S") +
xlab("Day") + ylab("Hour")
There are more examples of this type of scale in ?scale_datetime, which will point you to ?strptime for an explanation of the date and time formatting codes.
You can tweak the date axes using scale_datetime. The examples at the end are quite illustrative.
http://had.co.nz/ggplot2/scale_datetime.html

Axis Color of Date Histogram in R

I have successfullly created a histogram using a date field.
hist(df.sat$created_at, breaks="hours", freq=T, xlab="Time",
main="Sat Volume")
My issue is that when I attempt to fill in the bars using col="red" both the bars and both the x/y axes change to red, when I only want the bars. What is the best way way only fill in the bars?
Here are some data:
> dput(df.sat$created_at[sample(c(1:9000), 50)])
structure(list(sec = c(41, 3, 13, 11, 49, 55, 19, 21, 6, 15,
54, 45, 45, 39, 50, 27, 35, 25, 22, 35, 42, 31, 45, 29, 1, 3,
8, 47, 38, 2, 13, 29, 34, 42, 15, 19, 3, 39, 41, 12, 34, 50,
15, 27, 0, 29, 47, 26, 21, 5), min = c(46L, 38L, 4L, 35L, 26L,
56L, 9L, 52L, 51L, 15L, 49L, 3L, 41L, 59L, 30L, 30L, 30L, 53L,
25L, 51L, 23L, 38L, 30L, 3L, 43L, 33L, 36L, 52L, 0L, 21L, 27L,
22L, 51L, 31L, 0L, 37L, 3L, 2L, 12L, 3L, 45L, 13L, 59L, 10L,
11L, 7L, 41L, 21L, 5L, 20L), hour = c(14L, 16L, 18L, 15L, 15L,
16L, 16L, 18L, 18L, 13L, 18L, 16L, 14L, 13L, 16L, 15L, 18L, 17L,
18L, 18L, 16L, 17L, 17L, 19L, 15L, 18L, 17L, 18L, 19L, 17L, 16L,
17L, 18L, 20L, 18L, 15L, 14L, 14L, 18L, 18L, 19L, 19L, 16L, 15L,
17L, 17L, 15L, 17L, 17L, 17L), mday = c(9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L), mon = c(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, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L), year = c(111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L,
111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L,
111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L,
111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L,
111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L), wday = c(6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L), yday = c(98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L,
98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L,
98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L,
98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L,
98L), isdst = c(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, 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)), .Names = c("sec", "min", "hour", "mday",
"mon", "year", "wday", "yday", "isdst"), class = c("POSIXlt",
"POSIXt"), tzone = c("America/New_York", "EST", "EDT"))
You'll have to get around it a bit by plotting the histogram first and the axes later :
hist(Data, breaks="hours", freq=T, xlab="Time", col="red",
main="Sat Volume",axes=F)
Axis(Data,col="black",side=1)
axis(2,col="black")
Reason to use the generic Axis(), is that it takes into account that your variable is a TimeDate class. The default axis() doesnt.
EDIT :
FYI, this behaviour is only to be seen with histograms where DateTime classes are used on the X axis. The default hist() function doesn't change the color of the axis when using a fill color for the bars.
Plot the histogram without axes and then add them in later:
hist(dat, breaks="hours", freq=TRUE, col = "red", axes = FALSE)
axis.POSIXct(side = 1, dat)
axis(2)

Resources