Visualizing time series in spirals using R or Python?

Does anyone know how to do this in R? That is, does this cyclic data represent from the left section to the right section?

http://cs.lnu.se/isovis/courses/spring07/dac751/papers/TimeSpiralsInfoVis2001.pdf

enter image description here

Here are some sample data.

Day = c(rep(1,5),rep(2,5),rep(3,5)) Hour = rep(1:5,3) Sunlight = c(0,1,2,3,0,1,2,3,2,1,0,0,4,2,1) data = cbind(Day,Hour,Sunlight) 

enter image description here

+6
source share
2 answers

It looks pretty close:

 # sample data - hourly for 10 days; daylight from roughly 6:00am to 6:00pm set.seed(1) # for reproducibility Day <- c(rep(1:10,each=24)) Hour <- rep(1:24) data <- data.frame(Day,Hour) data$Sunlight <- with(data,-10*cos(2*pi*(Hour-1+abs(rnorm(240)))/24)) data$Sunlight[data$Sunlight<0] <- 0 library(ggplot2) ggplot(data,aes(x=Hour,y=10+24*Day+Hour-1))+ geom_tile(aes(color=Sunlight),size=2)+ scale_color_gradient(low="black",high="yellow")+ ylim(0,250)+ labs(y="",x="")+ coord_polar(theta="x")+ theme(panel.background=element_rect(fill="black"),panel.grid=element_blank(), axis.text.y=element_blank(), axis.text.x=element_text(color="white"), axis.ticks.y=element_blank()) 
+9
source

I know how to do this in Python. I find the scatter plot from matplotlib good for this kind of thing. Here is an example:

 import matplotlib.pyplot as plt import numpy as np period = 0.5 f = np.arange(0, 100, 0.03) // Data range z = np.sin(f) // Data a = f*np.sin(period*f); b = f*np.cos(period*f); fig = plt.figure() ax = plt.subplot(111) fig.add_subplot(ax) ax.scatter(a, b, c=z, s=100, edgecolors='none') plt.show() 

You can change the period to change the number of revolutions in the spiral. a and b draw a spiral while z contains the actual data (in this example, a sinusoid).

Example

+7
source

Source: https://habr.com/ru/post/979196/


All Articles