plot - Plotting a continuous of time data in R -
i trying plot distribution of turtle nesting activity on night using ggplot, want exclude times 8am - 6pm. also, need x-axis start @ 7pm , end @ 7am.
my code is
ggplot(sub.1) + geom_bar(aes(x = sub.1$time)) + scale_x_continuous(expand = c(0, 0), limits = c(0, 23), breaks = seq(0, 23, 1)) + xlab("hour") + ylab ("frequency")
any assistance appreciated.
try this. i'll post comments in there when chance. hope helps!
# example data samplehours <- sample(1:23, 3000, replace = true) # keep wanted hours includedhours <- c(19:23, 1:7) index <- samplehours %in% includedhours # create dataframe sub.1 <- data.frame(hour = samplehours[index]) # change factor levels sub.1$hour <- as.factor(sub.1$hour) factorlevels <- c(19:23, 1:7) levels(sub.1$hour) <- factorlevels # plot library(ggplot2) ggplot(sub.1) + geom_bar(aes(x = sub.1$hour)) + xlab("hour") + ylab ("frequency")
edit
changed part identify hours keep, not ones exclude. think makes easier follow
Comments
Post a Comment