在R中绘制并填充棋盘状区域(和类似物) [英] Plot and fill chessboard-like area (and the similars) in R

查看:185
本文介绍了在R中绘制并填充棋盘状区域(和类似物)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些关于如何绘制2D数字并将其有效填充到 R 中的建议。我需要形象化一些数学上的怪癖,例如Sierpiński垫圈或简单的棋盘 - 并且可以得到如下效果:






我想过使用复数来定义点,但仍然没有清楚的想法如何填充特定区域(例如以两种不同的颜色)。 解决方案 div>

类似的东西?从表示数据的矩阵开始

pre $ 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

然后融化/绘图:

$ (b)b



$ b $ library $(
$) var2,fill = value))+ geom_tile()



你在找什么?


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 gasket or a simple chessboard - and receive the effect similar to the following:

or

I thought about using the complex numbers to define the points but still have no clear idea how to fill particular areas (e.g. in two different colours).

解决方案

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()

Is that what you're looking for?

这篇关于在R中绘制并填充棋盘状区域(和类似物)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆