创建自定义形状
我对此有点迷失,我尝试过使用 geom_polygon 但连续的尝试似乎比前一次更糟糕。
我试图重新创建的图像是这样的,颜色并不重要,但位置是:
除了创建它之外,我还需要能够用文本标记每个元素。
在这一点上,我并不期待一个解决方案(尽管这将是理想的),但指针或类似的示例将非常有帮助。
我使用的一种选择是修改scale_shape并使用1,1作为坐标。但一直坚持添加标签。
我使用 ggplot 执行此操作的原因是因为我正在逐个公司生成记分卡。这只是其他绘图的 4 x 10 网格中的一个绘图(使用 PushViewport)
注意:金字塔的顶层也可以是类似大小的矩形。
完全披露:这也发布到 ggplot2 邮件列表中。 (如果收到回复我会更新)
I'm a bit lost on this one, I've tried messing around with geom_polygon but successive attempts seem worse than the previous.
The image that I'm trying to recreate is this, the colours are unimportant, but the positions are:
In addition to creating this, I also need to be able to label each element with text.
At this point, I'm not expecting a solution (although that would be ideal) but pointers or similar examples would be immensely helpful.
One option that I played with was hacking scale_shape and using 1,1 as coords. But was stuck with being able to add labels.
The reason I'm doing this with ggplot, is because I'm generating scorecards on a company by company basis. This is only one plot in a 4 x 10 grid of other plots (using pushViewport)
Note: The top tier of the pyramid could also be a rectangle of similar size.
Full Disclosure: This was also posted to the ggplot2 mailing list. (I'll update if I receive a response)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是我提出的解决方案。创建一系列多边形数据,并使用
geom_polygon()
来绘制它们。使用geom_text()
绘制文本标签。使用
cluster
包中的ellipsoidhull()
创建椭圆。您需要通过删除图例、网格线、轴标签等来修改绘图美观性。
Here is my proposed solution. Create a series of polygon data, and use
geom_polygon()
to plot these. Plot the text labels withgeom_text()
.Create the ellipse with
ellipsoidhull()
, in thecluster
package.You will want to modify the plot aesthetics by removing the legend, gridlines, axis labels, etc.
对于网格图形,
此外,网格视口可用于在同一页面上放置不同的对象。例如,
With grid graphics,
Further, Grid viewports can be used to place different objects on the same page. For instance,
似乎您可以使用
geom_path()
和geom_segment()
的组合,因为您知道或可以合理地猜测图形/图表上每个主要点的坐标位置/thingamajigger 在那里。也许这样的东西会起作用?构造的 data.frame 包含上面形状的轮廓(我选择了顶部的矩形...我相信如果您真的想要的话,您可以找到一种简单的方法来生成近似圆的点。然后使用geom_segment()
根据需要划分大形状编辑:
qplot()
在 ggplot2 3.4.0 中已弃用。使用 ggplot aes 的相同代码:It seems like you could use a combination of
geom_path()
andgeom_segment()
since you either know or can reasonably guesstimate the coordinate locations for each major point on your graph/chart/thingamajigger up there. Maybe something like this would work? The data.frame that was constructed contains the outline of the shape above (I opted for the rectangle at the top...I'm sure you could find an easy way to generate the points to approximate a circle if you really wanted. Then usegeom_segment()
to divvy up that large shape as you need.Edit:
qplot()
was deprecated in ggplot2 3.4.0. Here is the same code using ggplot aes: