Plot and fill chessboard-like area (and the similars) in R

前端 未结 2 1210
梦毁少年i
梦毁少年i 2021-01-15 02:42

I need some suggestion of how to plot 2D figures and fill them effectively in R. I need to visualize some mathematical \"oddities\", for example the Sierpiński

2条回答
  •  一向
    一向 (楼主)
    2021-01-15 03:10

    Something like so? Start with a matrix representing your data

    mx <- matrix(rep(c(T, F), 5), nrow=3, ncol=3)
    #      [,1]  [,2]  [,3]
    # [1,]  TRUE FALSE  TRUE
    # [2,] FALSE  TRUE FALSE
    # [3,]  TRUE FALSE  TRUE         
    

    and then melt/plot:

    library(reshape2)
    library(ggplot2)
    ggplot(melt(mx), aes(x=Var1, y=Var2, fill=value)) + geom_tile()
    

    enter image description here

    Is that what you're looking for?

提交回复
热议问题