Can anyone help me out on how can I create a punchcard plot in R (without using ggplot)?
Just like this one that was made in python:
The black border looks good on the original figure. It can be reproduced with symbols()
. sqrt((pctable$value / max(pctable$value)) / pi)
added in order to make sure that values are proportional to the symbols' surface rather than to their radius.
pctable <- data.frame(expand.grid(weekday=c("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"),
day=1:22), value=abs(rnorm(nrow(pctable), 20, 30)))
par(list(las=1, mar=c(6,6,1,1), mgp=c(4.5,1,0)))
bubble.size <- sqrt((pctable$value / max(pctable$value)) / pi)
symbols(pctable$day, pctable$weekday, circles=bubble.size,
inches=.2, fg="black", bg="blue", yaxt="n", xaxt="n", xlab="Day", ylab="Weekday")
axis(1, at=1:22, labels=c(1:22))
axis(2, at=1:7,labels=rev(c("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday")), cex.axis=0.7)
How about this?
pctable<-data.frame(expand.grid(c("monday","tuesday","wednesday","thursday","friday","saturday","sunday"),1:22))
colnames(pctable)<-c("weekday","day")
pctable$value=rnorm(nrow(pctable),15,8)
plot(pctable$day,pctable$weekday,cex=pctable$value/(max(pctable$value)/5), col=rgb(0,0,1), pch=19, yaxt="n", xaxt="n")
axis(1, at=1:22, labels=c(1:22))
axis(2, at=1:7, labels=c("monday","tuesday","wednesday","thursday","friday","saturday","sunday"), cex.axis=0.7)
You will need to probably have a function to return the correct cex='?' value for your scale, it won't resize.
Out of interest, why not ggplot?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With