1961 2

[问答] 想问一下如何用R做类似的图? [推广有奖]

  • 0关注
  • 0粉丝

大专生

5%

还不是VIP/贵宾

-

威望
0
论坛币
96 个
通用积分
1.0005
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
888 点
帖子
38
精华
0
在线时间
20 小时
注册时间
2017-2-5
最后登录
2020-1-13

楼主
想学好R的徐二狗 发表于 2019-7-17 22:17:00 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
图如下,大家能不能启发一下我?谢谢啦
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:如何用

选择性清除分析做图.png (102.5 KB)

选择性清除分析做图.png

本帖被以下文库推荐

沙发
owenqi 在职认证  学生认证  发表于 2019-7-18 03:30:43
关键词应该是:Marginal Plot, 用ggplot2的话应该可以,给你个网上的例子

library(cowplot)
library(ggplot2)
# Main plot
pmain <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species))+
  geom_point()+
  ggpubr::color_palette("jco")
# Marginal densities along x axis
xdens <- axis_canvas(pmain, axis = "x")+
  geom_density(data = iris, aes(x = Sepal.Length, fill = Species),
               alpha = 0.7, size = 0.2)+
  ggpubr::fill_palette("jco")
# Marginal densities along y axis
# Need to set coord_flip = TRUE, if you plan to use coord_flip()
ydens <- axis_canvas(pmain, axis = "y", coord_flip = TRUE)+
  geom_density(data = iris, aes(x = Sepal.Width, fill = Species),
               alpha = 0.7, size = 0.2)+
  coord_flip()+
  ggpubr::fill_palette("jco")
p1 <- insert_xaxis_grob(pmain, xdens, grid::unit(.2, "null"), position = "top")
p2<- insert_yaxis_grob(p1, ydens, grid::unit(.2, "null"), position = "right")
ggdraw(p2)

藤椅
owenqi 在职认证  学生认证  发表于 2019-7-18 03:32:20
关键字应该是 marginal plot, 用lattice+latticeExtra或者ggplot2+ggExtra应该都能实现,网上有一个例子,你可以改改
  1. library(cowplot)
  2. library(ggplot2)
  3. # Main plot
  4. pmain <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species))+
  5.   geom_point()+
  6.   ggpubr::color_palette("jco")
  7. # Marginal densities along x axis
  8. xdens <- axis_canvas(pmain, axis = "x")+
  9.   geom_density(data = iris, aes(x = Sepal.Length, fill = Species),
  10.                alpha = 0.7, size = 0.2)+
  11.   ggpubr::fill_palette("jco")
  12. # Marginal densities along y axis
  13. # Need to set coord_flip = TRUE, if you plan to use coord_flip()
  14. ydens <- axis_canvas(pmain, axis = "y", coord_flip = TRUE)+
  15.   geom_density(data = iris, aes(x = Sepal.Width, fill = Species),
  16.                alpha = 0.7, size = 0.2)+
  17.   coord_flip()+
  18.   ggpubr::fill_palette("jco")
  19. p1 <- insert_xaxis_grob(pmain, xdens, grid::unit(.2, "null"), position = "top")
  20. p2<- insert_yaxis_grob(p1, ydens, grid::unit(.2, "null"), position = "right")
  21. ggdraw(p2)
复制代码
已有 1 人评分论坛币 收起 理由
cheetahfly + 20 精彩帖子

总评分: 论坛币 + 20   查看全部评分

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-31 16:11