r - 如何用ggplot删除空白面?
问题描述
我正在使用 facet_grid 用 ggplot 做 geom_point,但是我的 facet 是空的,我不知道如何删除它们或如何构造我的数据以使其没有空 facet?
这是我的数据示例:
data = data.frame(
F1=c(0.69, 0.59, 0.6 , 0.52, 0.56, 0.58, 0.52, 0.53, 0.41, 0.57,
0.54, 0.38, 0.48, 0.31, 0.35,
0.43, 0.36, 0.38, 0.23, 0.48, 0.55, 0.48, 0.49, 0.46, 0.49,
0.52, 0.48, 0.48, 0.35, 0.5 ,
0.51, 0.58, 0.51, 0.59, 0.51, 0.57, 0.5 , 0.59, 0.47, 0.51,
0.61, 0.58, 0.61, 0.59, 0.61, 0.67, 0.6 , 0.59, 0.47, 0.61,
0.61, 0.52, 0.53, 0.60,0.62, 0.53, 0.62, 0.63, 0.24, 0.38),
F2 = c(0.01, 0.01, 0.02, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01,
0.42, 0.35, 0.43, 0.31, 0.34, 0.41, 0.34, 0.34, 0.42, 0.39, 0.44, 0.43,
0.49, 0.43, 0.42, 0.53, 0.41, 0.42, 0.50, 0.40 ,
0.53, 0.58, 0.57, 0.55, 0.51, 0.65, 0.51, 0.52, 0.62, 0.49,
0.63, 0.68, 0.67, 0.66, 0.61, 0.66, 0.61, 0.62, 0.62, 0.49,
0.84, 0.65, 0.69, 0.56, 0.72, 0.61, 0.73, 0.68, 0.72, 0.72),
s1= c(rep(c("a"),10),
rep(c("b"),10),
rep(c("c"),10),
rep(c("d"),10),
rep(c("f"),10),
rep(c("g"),10)),
s2= c(rep(c("g1"),20),
rep(c("g2"),40)),
M=rep(c("M1",
"M2",
"M3",
"M4",
"M5",
"M6",
"M7",
"M8",
"M9",
"M10"),6))
我的代码:
ggplot (data, aes (x = F1, y = F2, shape = M)) +
facet_grid(s2 ~ s1) + scale_shape_manual(values=c(7,13,23,0,8,1,15,2,17,3,25))+
geom_point ()
我明白了 :
解决方案
我不知道为什么 facet_wrap 不起作用
下面的代码产生你想要的
p <- ggplot (data, aes (x = F1, y = F2, shape = M))
p <- p + geom_point ()
p <- p + facet_wrap(s2 ~ s1,ncol=2) + scale_shape_manual(values=c(7,13,23,0,8,1,15,2,17,3,25))
p
推荐阅读
- qt - 绑定类型:是否可以监听临时覆盖的绑定?
- javascript - 将某些访问者重定向到另一个域,同时保留整个查询字符串
- javascript - 在 JS 中转换可见性/不透明度
- graphql - 使用 gatsbyjs GraphQL 查询特定文件夹中的所有图像
- python - 更新了 spyder 但软件包正在消失
- mysql - MySQL 使用 AND 或 HAVING 过滤来自 SubSelect 的结果
- javascript - 元素 div 上的单击事件,除了子元素
- html - Div Tile 用文本扩展,我该如何防止这种情况(尝试溢出:隐藏)
- python - Creating a encrypting function to encrypt a string in python
- ruby-on-rails - What to do about "is not an ActiveModel-compatible object. It must implement :to_partial_path." error when trying to use render_to_string in a PORO