how to graph levels in x and y coordinates (level plot)? - r

I have an extensive set of levels of my interest variable (over a year of collection). I would like to plot these levels (there are 3 levels) in coordinates X (date of the year- the day of the year) and Y (time of day- hour).
I am encountering difficulties due to the collection period and also to put a legend with each level.
I would be grateful if anyone could indicate how to compose this graph
My matrix data:
Hour;28/jun;29/jun;30/jun;01/jul;02/jul;03/jul;04/jul;05/jul;06/jul;07/jul;08/jul;09/jul;10/jul;11/jul;12/jul;13/jul;14/jul;15/jul;16/jul;17/jul;18/jul;19/jul;20/jul;21/jul;22/jul;23/jul;24/jul;25/jul;26/jul;27/jul;28/jul;29/jul;30/jul;31/jul;01/ago;02/ago;03/ago;04/ago;05/ago;06/ago;07/ago;08/ago;09/ago;10/ago;11/ago;12/ago;13/ago;14/ago;15/ago;16/ago;17/ago;18/ago;19/ago;20/ago;21/ago;22/ago;23/ago;24/ago;25/ago;26/ago;27/ago;28/ago;29/ago;30/ago;31/ago;01/set;02/set;03/set;04/set;05/set;06/set;07/set;08/set;09/set;10/set;11/set;12/set;13/set;14/set;15/set;16/set;17/set;18/set;19/set;20/set;21/set;22/set;23/set;24/set;25/set;26/set;27/set;28/set;29/set;30/set;01/out;02/out;03/out;04/out;05/out;06/out;07/out;08/out;09/out;10/out;11/out;12/out;13/out;14/out;15/out;16/out;17/out;18/out;19/out;20/out;21/out;22/out;23/out;24/out;25/out;26/out;27/out;28/out;29/out;30/out;31/out;01/nov;02/nov;03/nov;04/nov;05/nov;06/nov;07/nov;08/nov;09/nov;10/nov;11/nov;12/nov;13/nov;14/nov;15/nov;16/nov;17/nov;18/nov;19/nov;20/nov;21/nov;22/nov;23/nov;24/nov;25/nov;26/nov;27/nov;28/nov;29/nov;30/nov;01/dez;02/dez;03/dez;04/dez;05/dez;06/dez;07/dez;08/dez;09/dez;10/dez;11/dez;12/dez;13/dez;14/dez;15/dez;16/dez;17/dez;18/dez;19/dez;20/dez;21/dez;22/dez;23/dez;24/dez;25/dez;26/dez;27/dez;28/dez;29/dez;30/dez;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3;3;5;0;3;3;3;3;3;3;3;0;3;0;3;3;3;3;3;3;0;0;3;0;3;3;0;0;0;3;3;3;3;3;0;0;0;0;3;3;3;3;3;3;3;3;0;0;5;5;5;3;5;3;3;3;3;3;5;5;3;3;3;3;5;0;3;3;0;3;3;3;3;3;3;3;3;3;0;0;3;3;3;3;3;0;0;0;3;3;3;0;0;3;3;0;3;3;3;3;0;3;3;3;3;0;0;3;3;0;3;3;3;3;3;3;0;0;3;0;0;0;3;3;3;3;3;3;0;3;3;0;0;3;3;3;3;0;0;0;3;3;3;3;3;0;3;3;3;0;0;3;3;3;3;3;3;3;3;3;3;3;3;3;3;3;0;0;3;0;3;3;3;3
23.5;3;3;3;3;3;3;0;0;0;0;0;3;0;0;3;0;0;3;3;3;3;3;3;3;0;3;0;3;3;0;3;3;3;0;0;3;0;3;3;0;0;0;3;3;3;3;3;0;0;0;0;3;5;5;0;3;3;5;3;0;0;3;5;5;3;5;3;3;3;3;3;0;5;3;3;3;3;5;0;3;3;0;3;3;3;3;3;3;3;3;3;0;0;3;3;3;3;3;0;0;0;3;3;3;3;0;3;3;0;3;3;3;3;0;3;3;3;3;0;0;3;3;0;3;3;3;3;3;3;0;0;3;0;0;0;3;3;3;3;3;3;0;3;3;0;0;3;3;3;3;3;0;0;3;3;3;3;3;0;3;3;3;0;0;3;3;3;3;3;3;3;3;3;3;3;3;3;3;3;0;0;3;0;3;3;3;3
I tried it: http://www.r-graph-gallery.com/27-levelplot-with-lattice/
dados=as.matrix(read.table("1_3.txt", header=T, sep = ";"))
head(dados,5)
heatmap(dados, Colv = NA, Rowv = (NA), scale="none", xlab = "Date", ylab = "Hour")
But the information on the x- and y-axis becomes unclear and no caption appears
And...https://www.r-graph-gallery.com/133-demineur-dataart/
dados <- read.table("1_3.txt", header=T, sep = ";")
y <- dados$Hour
x <- dados[,-1]
par(mar=c(0,0,0,0))
data <- expand.grid(X=x, Y=y)
plot(data[,1],data[,2],xaxt="n",yaxt="n", xlab="", ylab="", bty="n", mar=c(0,0,0,0), pch=20,cex=3,col=rgb(0.2,0.2,0.4,sample(seq(0.2,1,0.001), 10000,replace=T)))
But "xlab" matched by multiple actual arguments

It was not very easy for me to copy your data to play around with, but I managed. Please consider using the output of dput(your_data) in future questions.
Since somebody tagged this question with ggplot2, I'm going to assume you want to achieve this heatmap of your matrix in ggplot. Assuming dados is your matrix, we'll first melt it from a wide format to a long format:
df <- reshape2::melt(dados, id.vars = "Hour")
Then the next thing to do would be to use ggplot with a raster geom:
ggplot(df, aes(x = variable, y = Hour, fill = value)) +
geom_raster()
Which gave me the following plot:
As is clear to see, the x-axis is quite overcrowded. To fix this, we need to get your annotation of the date into a format that R understands. I'm not really good with dates in R, but you might try something like the following:
months <- substr(as.character(df$variable), 4, nchar(as.character(df$variable)))
months <- factor(months, levels = unique(months))
levels(months) <- 6:12
months <- as.numeric(as.character(months))
days <- substr(as.character(df$variable), 1, 2)
df$date <- as.Date(paste0(months, "-", days), format = "%m-%d")
And now you can plot with the date as the x axis:
ggplot(df, aes(x = date, y = Hour, fill = value)) +
geom_raster()
And that should be a decent heatmap to get you started.

It worked very well: I just renamed my columns of dates in the original data. I put the name of each month in the first hour of the first day. The rest I left out.
df <- reshape2::melt(dados, id.vars = "Hour")
f1 <- ggplot(df, aes(x = variable, y = Hour, fill = value)) +
geom_raster()+
theme(legend.title=element_blank()) +
theme(text=element_text(family="Times New Roman", size=12))
f1
f1 + scale_x_discrete(breaks=c("Jul","Aug", "Sep", "Oct", "Nov", "Dec"))

Related

Plotting geom_segment with position_dodge

I have a data set with information of where individuals work at over time. More specifically, I have information on the interval at which individuals work in a given workplace.
library('tidyverse')
library('lubridate')
# individual A
a_id <- c(rep('A',1))
a_start <- c(201201)
a_end <- c(201212)
a_workplace <-c(1)
# individual B
b_id <- c(rep('B',2))
b_start <- c(201201, 201207)
b_end <- c(201206, 201211)
b_workplace <-c(1, 2)
# individual C
c_id <- c(rep('C',2))
c_start <- c(201201, 201202)
c_end <- c(201204, 201206)
c_workplace <-c(1, 2)
# individual D
d_id <- c(rep('D',1))
d_start <- c(201201)
d_end <- c(201201)
d_workplace <-c(1)
# final data frame
id <- c(a_id, b_id, c_id, d_id)
start <- c(a_start, b_start, c_start, d_start)
end <- c(a_end, b_end, c_end, d_end)
workplace <- as.factor(c(a_workplace, b_workplace, c_workplace, d_workplace))
mydata <- data.frame(id, start, end, workplace)
mydata_ym <- mydata %>%
mutate(ymd_start = as.Date(paste0(start, "01"), format = "%Y%m%d"),
ymd_end0 = as.Date(paste0(end, "01"), format = "%Y%m%d"),
day_end = as.numeric(format(ymd_end0 + months(1) - days(1), format = "%d")),
ymd_end = as.Date(paste0(end, day_end), format = "%Y%m%d")) %>%
select(-ymd_end0, -day_end)
I would like a plot where I can see the patterns of how long each individual works at each workplace as well as how they move around. I tried plotting a geom_segment as I have information of start and end date the individual works in each place. Besides, because the same individual may work in more than one place during the same month, I would like to use position_dodge to make it visible when there is overlap of different workplaces for the same id-time. This was suggested in this post here: Ggplot (geom_line) with overlaps
ggplot(mydata_ym) +
geom_segment(aes(x = id, xend = id, y = ymd_start, yend = ymd_end),
position = position_dodge(width = 0.1), size = 2) +
scale_x_discrete(limits = rev) +
coord_flip() +
theme(panel.background = element_rect(fill = "grey97")) +
labs(y = "time", title = "Work affiliation")
The problem I am having is that: (i) the position_dodge doesn't seem to be working, (ii) I don't know why all the segments are being colored in black. I would expect each workplace to have a different color and a legend to show up.
If you include colour = workplace in the aes() mapping for geom_segment you get colours and a legend and some dodging, but it doesn't work quite right (it looks like position_dodge only applies to x and not xend ... ? this seems like a bug, or at least an "infelicity", in position_dodge ...
However, replacing geom_segment with an appropriate use of geom_linerange does seem to work:
ggplot(mydata_ym) +
geom_linerange(aes(x = id, ymin = ymd_start, ymax = ymd_end, colour = workplace),
position = position_dodge(width = 0.1), size = 2) +
scale_x_discrete(limits = rev) +
coord_flip()
(some tangential components omitted).
A similar approach is previously documented here — a near-duplicate of your question once the colour= mapping is taken care of ...

Plotting of cumulative data of multiple year in R

I have daily rainfall data which I have converted to yearwise cumulative value using following code
library(seas)
library(data.table)
library(ggplot2)
#Loading data
data(mscdata)
dat <- (mksub(mscdata, id=1108447))
dat$julian.date <- as.numeric(format(dat$date, "%j"))
DT <- data.table(dat)
DT[, Cum.Sum := cumsum(rain), by=list(year)]
df <- cbind.data.frame(day=dat$julian.date,cumulative=DT$Cum.Sum)
But when I am trying to plot, it gives me weired output like
#Plotting using base R
df <- df[order(df[,1]),]
plot(df$day, df$cumulative, type="l", xlab="Day", ylab="Cumulative rainfall")
Same I am getting using ggplot2 also like
#Plotting using ggplot2
ggplot(df, aes(x = day, y = cumulative)) + geom_line()
But I want to get lines for every year may be in grey colour and mean value over the years in red colour like the following figure
How to achieve this?
Add the group aesthetic to tell ggplot to group by the year and add stat_summary to draw the red line (without the grouping).
library(ggplot2)
ggplot(DT, aes(x = julian.date, y = Cum.Sum, group=year)) +
geom_line(col="grey") +
labs(x="Date", y="Cumulative sum") +
stat_summary(aes(group=NULL), fun="mean", geom="line", col="red", se="none", lwd=1)
For base graphics, it's a little more involved:
par(mar=c(4,3.5,1,1))
plot(df$day, df$cumulative, type="n", xlab="Day", ylab="Cumulative rainfall", las=1)
grid()
lapply(split(df, df$year), FUN=function(x)
with(x, lines(day, cumulative, col="grey", lwd=0.5)))
with(aggregate(cumulative~day, FUN=mean, data=df),
lines(x=day, y=cumulative, lwd=2, col="red"))
So, as you can see, you lost the group in geom_line. Without group, ggplot will connect all dots sharing with the axis.x.
Here is an example to add 'year' as the group and calculate the mean value for each day.
library(reshape2)
data(mscdata)
dat <- (mksub(mscdata, id=1108447))
dat$julian.date <- as.numeric(format(dat$date, "%j"))
DT <- data.table(dat)
DT[, Cum.Sum := cumsum(rain), by=list(year)]
dt <- cbind.data.frame(day=dat$julian.date,cumulative=DT$Cum.Sum,year=DT$year)
TB <- melt(dt, id.vars = c('day','year'))
Mean_l = colMeans(reshape(TB[c("day",'year','value')],timevar='day',idvar = 'year', direction = 'wide'),na.rm = T)
Mean_l= Mean_l[-1]
Mean_l <- data.frame(day=c(1:length(Mean_l)),Mean_l)
TB_f <- data.frame(TB,avr=Mean_l$Mean_l[match(TB$day,Mean_l$day)])
ggplot(TB_f,aes(day,value))+ geom_line(aes(group=year))+ geom_line(aes(y=avr),color='red')+ theme_light()

R - extracting time only from xts, zoo and POSIXct

I am analyzing day to day data to see when the value would be lower. I set each day as categorical variable so I can differentiate each day. But I want to get each day plotted on top of another day instead of one continuous graph as shown below.
Data set:
Value Day
2013-01-03 01:55:00 0.35435715 1
2013-01-03 02:00:00 0.33018654 1
2013-01-03 02:05:00 0.38976118 1
2013-01-04 02:10:00 0.45583868 2
2013-01-04 02:15:00 0.29290860 2
My current ggplot code is as follows:
g <- ggplot(data = Data, aes(x = Index, color = Dates)) +
geom_line(y = Data$Value) +
scale_x_datetime(date_breaks = TimeIntervalForGraph, date_labels = "%H") +
xlab("Time") +
ylab("Random value")
I would really appreciate if anyone can guide me on how I can turn my x-axis into 24hrs time series so that I can plot each day on the same graph to see when the value is lower during the 24 hrs.Thanks in advance.
Method tried:
I tried creating an 3rd column with time only, for some reasons the following codes didnt work:
time <- format(index(x), format = "%H:%M"))
data <- cbind(data, time)
You need a way of summarising the data for each hour of the day. Here are some approaches you're probably looking for:
library(xts)
library(data.table)
library(ggplot2)
tm <- seq(as.POSIXct("2017-08-08 17:30:00"), by = "5 mins", length.out = 10000)
z <- xts(runif(10000), tm, dimnames = list(NULL, "vals"))
DT <- data.table(time = index(z), coredata(z))
# note the data.table syntax is different:
DT[, hr := hour(time)]
# Plot the average value by hour:
datByHour <- DT[, list(avgval = mean(vals)), by = c("hr")]
# Use line plot if you have one point per hour:
g <- ggplot(data = datByHour, aes(x = hr, y = avgval, colour = avgval)) +
geom_line()
datByHour <- DT[, list(avgval = mean(vals)), by = c("hr")]
# visualise the distribution by hour:
g2 <- ggplot(data = DT, aes(x = hr, y = vals, group = hr)) +
geom_boxplot()
Please try the following and let me know if it works (here I am taking tm time column as given):
Data$tm = strftime(Data$tm, format="%H:%M:%S")
library(ggplot2)
ggplot(Data, aes(x = tm, y = Value, group = Day, colour = Day)) +
geom_line() +
theme_classic()

R heat map of annual time series by entire year

I am trying to make a heatmap of several years of daily averages of salinity in an estuary in R.
I would like the format to include month on the x-axis and year on the y-axis, so each Jan 1st directly above another Jan. 1st. In other words, NOT like a typical annual calendar style (not like this: http://www.r-bloggers.com/ggplot2-time-series-heatmaps/).
So far I have only been able to plot by the day of the year using:
{r}
d <- read.xlsx('GC salinity transposed.xlsx', sheetName = "vert-3", header = TRUE, stringsAsFactors = FALSE, colClasses = c("integer", "integer", "numeric"), endRow = 2254)
{r}
ggplot(d, aes(x = Day.Number, y = Year)) + geom_tile(aes(fill = Salinity)) + scale_fill_gradient(name = 'Mean Daily Salinity', low = 'white', high = 'blue') + theme(axis.title.y = element_blank())
And get this:
heat map not quite right
Could someone please tell me a better way to do this - a way that would include month, rather than day of the year along the x-axis? Thank you. New to R.
The lubridate package comes in handy for stuff like this. Does this code do what you want? I'm assuming you only have one salinity reading per month and there's no need to average across multiple values in the same month.
library(lubridate)
library(ggplot2)
# Define some data
df <- data.frame(date = seq.Date(from = as.Date("2015-01-01"), by = 1, length.out = 400),
salinity = runif(400, min=5, max=7))
# Create fields for plotting
df$day <- paste0(ifelse(month(df$date)<10,"0",""),
month(df$date),
"-",
ifelse(day(df$date)<10,"0",""),
day(df$date))
df$month <- paste0(ifelse(month(df$date)<10,"0",""),
month(df$date))
df$year <- year(df$date)
library(lubridate)
library(ggplot2)
# Define some data
df <- data.frame(date = seq.Date(from = as.Date("2015-01-01"), by = 1, length.out = 400),
salinity = runif(400, min=5, max=7))
# Create fields for plotting
df$day <- paste0(ifelse(month(df$date)<10,"0",""),
month(df$date),
"-",
ifelse(day(df$date)<10,"0",""),
day(df$date))
df$month <- paste0(ifelse(month(df$date)<10,"0",""),
month(df$date))
df$year <- year(df$date)
#Plot results by month
ggplot(data=df) +
geom_tile(aes(x = month, y = year, fill = salinity)) +
scale_y_continuous(breaks = c(2015,2016))
#Plot results by day
ggplot(data=df) +
geom_tile(aes(x = day, y = year, fill = salinity)) +
scale_y_continuous(breaks = c(2015,2016))
Results by month:
Results by day (do you really want this? It's very hard to read with 366 x-axis values):

How to Create a Graph of Statistical Time Series

I have data in the following format:
Date Year Month Day Flow
1 1953-10-01 1953 10 1 530
2 1953-10-02 1953 10 2 530
3 1953-10-03 1953 10 3 530
I would like to create a graph like this:
Here is my current image and code:
library(ggplot2)
library(plyr)
library(reshape2)
library(scales)
## Read Data
df <- read.csv("Salt River Flow.csv")
## Convert Date column to R-recognized dates
df$Date <- as.Date(df$Date, "%m/%d/%Y")
## Finds Water Years (Oct - Sept)
df$WY <- as.POSIXlt(as.POSIXlt(df$Date)+7948800)$year+1900
## Normalizes Water Years so stats can be applied to just months and days
df$w <- ifelse(month(df$Date) %in% c(10,11,12), 1903, 1904)
##Creates New Date (dat) Column
df$dat <- as.Date(paste(df$w,month(df$Date),day(df$Date), sep = "-"))
## Creates new data frame with summarised data by MonthDay
PlotData <- ddply(df, .(dat), summarise, Min = min(Flow), Tenth = quantile(Flow, p = 0.05), TwentyFifth = quantile(Flow, p = 0.25), Median = quantile(Flow, p = 0.50), Mean = mean(Flow), SeventyFifth = quantile(Flow, p = 0.75), Ninetieth = quantile(Flow, p = 0.90), Max = max(Flow))
## Melts data so it can be plotted with ggplot
m <- melt(PlotData, id="dat")
## Plots
p <- ggplot(m, aes(x = dat)) +
geom_ribbon(aes(min = TwentyFifth, max = Median), data = PlotData, fill = alpha("black", 0.1), color = NA) +
geom_ribbon(aes(min = Median, max = SeventyFifth), data = PlotData, fill = alpha("black", 0.5), color = NA) +
scale_x_date(labels = date_format("%b"), breaks = date_breaks("month"), expand = c(0,0)) +
geom_line(data = subset(m, variable == "Mean"), aes(y = value), size = 1.2) +
theme_bw() +
geom_line(data = subset(m, variable %in% c("Min","Max")), aes(y = value, group = variable)) +
geom_line(data = subset(m, variable %in% c("Ninetieth","Tenth")), aes(y = value, group = variable), linetype = 2) +
labs(x = "Water Year", y = "Flow (cfs)")
p
I am very close but there are some issues I'm having. First, if you can see a way to improve my code, please let me know. The main problem I ran into was that I needed two dataframes to make this graph: one melted, and one not. The unmelted dataframe was necessary (I think) to create the ribbons. I tried many ways to use the melted dataframe for the ribbons, but there was always a problem with the aesthetic length.
Second, I know to have a legend - and I want one, I need to have something in the aesthetics of each line/ribbon, but I am having trouble getting that to work. I think it would involve scale_fill_manual.
Third, and I don't know if this is possible, I would like to have each month label in between the tick marks, not on them (like in the above image).
Any help is greatly appreciated (especially with creating more efficient code).
Thank you.
Something along these lines might get you close with base:
library(lubridate)
library(reshape2)
# simulating data...
Date <- seq(as.Date("1953-10-01"),as.Date("2010-10-01"),by="day")
Year <- year(Date)
Month <- month(Date)
Day <- day(Date)
set.seed(1)
Flow <- rpois(length(Date), 2000)
Data <- data.frame(Date=Date,Year=Year,Month=Month,Day=Day,Flow=Flow)
# use acast to get it in a convenient shape:
PlotData <- acast(Data,Year~Month+Day,value.var="Flow")
# apply for quantiles
Quantiles <- apply(PlotData,2,function(x){
quantile(x,probs=c(1,.9,.75,.5,.25,.1,0),na.rm=TRUE)
})
Mean <- colMeans(PlotData, na.rm=TRUE)
# ugly way to get month tick separators
MonthTicks <- cumsum(table(unlist(lapply(strsplit(names(Mean),split="_"),"[[",1))))
# and finally your question:
plot(1:366,seq(0,max(Flow),length=366),type="n",xlab = "Water Year",ylab="Discharge",axes=FALSE)
polygon(c(1:366,366:1),c(Quantiles["50%",],rev(Quantiles["75%",])),border=NA,col=gray(.6))
polygon(c(1:366,366:1),c(Quantiles["50%",],rev(Quantiles["25%",])),border=NA,col=gray(.4))
lines(1:366,Quantiles["90%",], col = gray(.5), lty=4)
lines(1:366,Quantiles["10%",], col = gray(.5))
lines(1:366,Quantiles["100%",], col = gray(.7))
lines(1:366,Quantiles["0%",], col = gray(.7), lty=4)
lines(1:366,Mean,lwd=3)
axis(1,at=MonthTicks, labels=NA)
text(MonthTicks-15,-100,1:12,pos=1,xpd=TRUE)
axis(2)
The plotting code really isn't that tricky. You'll need to clean up the aesthetics, but polygon() is usually my strategy for shaded regions in plots (confidence bands, whatever).
Perhaps this will get you closer to what you're looking for, using ggplot2 and plyr:
library(ggplot2)
library(plyr)
library(lubridate)
library(scales)
df$MonthDay <- df$Date - years( year(df$Date) + 100 ) #Normalize points to same year
df <- ddply(df, .(Month, Day), mutate, MaxDayFlow = max(Flow) ) #Max flow on day
df <- ddply(df, .(Month, Day), mutate, MinDayFlow = min(Flow) ) #Min flow on day
p <- ggplot(df, aes(x=MonthDay) ) +
geom_smooth(size=2,level=.8,color="black",aes(y=Flow)) + #80% conf. interval
geom_smooth(size=2,level=.5,color="black",aes(y=Flow)) + #50% conf. interval
geom_line( linetype="longdash", aes(y=MaxDayFlow) ) +
geom_line( linetype="longdash", aes(y=MinDayFlow) ) +
labs(x="Month",y="Flow") +
scale_x_date( labels = date_format("%b") ) +
theme_bw()
Edit: Fixed X scale and X scale label
(Partial answer with base plotting function and not including the min, max, or mean.) I suspect you will need to construct a dataset before passing to ggplot, since that is typical for that function. I already do something similar and then pass the resulting matrix to matplot. (It doesn't do that kewl highlighting, but maybe ggplot can do it>
HDL.mon.mat <- aggregate(dfrm$Flow,
list( dfrm$Year + dfrm$Month/12),
quantile, prob=c(0.1,0.25,0.5,0.75, 0.9), na.rm=TRUE)
matplot(HDL.mon.mat[,1], HDL.mon.mat$x, type="pl")

Resources