I am plotting a 4 dimensional data set. Beyond the x-axis and y-axis, I want to represent the 3rd and the 4th dimension by rectangles of different width and height. Can I do this with ggplot
? Thanks.
Here is one approach:
dd <- data.frame(x = (x <- 1:10),
y = x + rnorm(10), width = runif(10,1,2), height = runif(10,1,2))
ggplot(data = dd) +
geom_rect(aes(xmax = x + width/2, xmin = x - width/2,
ymax = y + height/2, ymin = y - height/2),
alpha =0.2, color = rgb(0,114,178, maxColorValue=256),
fill = rgb(0,114,178, maxColorValue=256)) +
coord_fixed() +
theme_bw()
You can try something like this. I use
geom_point
with shape =0 to simulate rectanglegeom_rect
to create ractangle centered around the pointshere my data (it would be better to provide some data)
d=data.frame(x=seq(1,10),
y=seq(1,10),
width=rep(c(0.1,0.5),each =5),
height=rep(c(0.8,0.9,0.4,0.6,0.7),each =2))
ggplot(data = d) +
geom_rect(aes(xmax = x + width, xmin = x-width,
ymax = y+height, ymin = y - height),
color = "black", fill = NA) +
geom_point(mapping=aes(x=x, y=y,size=height/width),
color='red',shape=0)+
theme_bw()
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