如何为ggplot中的每个点使用不同的形状 [英] How to use different shapes for every point in ggplot

查看:1118
本文介绍了如何为ggplot中的每个点使用不同的形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在绘制一个4维数据集。除了x轴和y轴,我想通过不同宽度和高度的矩形表示第3和第4维。我可以用 ggplot 来做到这一点吗?谢谢。



解决方案

以下是一种方法:

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


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

这篇关于如何为ggplot中的每个点使用不同的形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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