如何在GGPLOT中创建多彩背景?
我有一个包含多个组和EXP的数据集。状况。 (此处表示为group< - c(“ g1”,“ g2”)
和con< - c(“ a1”,“ a2”,“ a2”,“ b1”,“ b2”,“ b2” )
)我制作了一个3x3图矩阵,下面是其中一个图的一部分。图中的A1只是A1的导数骗局,不需要与A1的单独背景。
我想要的是给它们不同的颜色背景和框架,因此它们对读者更加友好。 (例如,以下输出但填充整个镀层区域[颜色填充的背景区分条件A,B,而彩色边框区分条件1,2]))如何在R中存档?
-----更新----
正如您所评论的那样,这是保留原始数据框架结构的演示数据。
(sep = " ")# I use csv in real data,
# here is just for better presentation
group animal_nr region con gene1 gene2 gene3
g1 101 x A1 10 15 100
g1 102 x A1 12 15 110
g1 103 x A1 9 16 90
g1 104 x A1 11 14 105
g1 201 x a1 10 15 100
g1 202 x a1 12 16 110
g1 203 x a1 9 16 90
g1 204 x a1 11 14 105
g1 105 x A2 -8 5 50
g1 106 x A2 -9 5.5 52
g1 107 x A2 -8 4 53
g1 108 x A2 0 6 52.8
g1 205 x a2 -8 5 50
g1 206 x a2 -9 5.5 52
g1 207 x a2 -8 4 53
g1 208 x a2 0 6 52.8
g1 109 x B1 2 15 29
g1 110 x B1 3 15.5 35
g1 111 x B1 1 16 33
g1 112 x B1 1.1 14 30
g1 209 x b1 2 15 29
g1 210 x b1 3 15.5 35
g1 211 x b1 1 16 33
g1 212 x b1 1.1 14 30
g1 113 x B2 -10 2 10
g1 114 x B2 -8 3 11
g1 115 x B2 -9 2 11.1
g1 116 x B2 -11 4 12
g2 301 x A1 10 15 100
g2 302 x A1 12 15 110
g2 303 x A1 9 16 90
g2 304 x A1 11 14 105
g2 401 x a1 10 15 100
g2 402 x a1 12 16 110
g2 403 x a1 9 16 90
g2 404 x a1 11 14 105
g2 305 x A2 -8 5 50
g2 306 x A2 -9 5.5 52
g2 307 x A2 -8 4 53
g2 308 x A2 0 6 52.8
g2 405 x a2 -8 5 50
g2 406 x a2 -9 5.5 52
g2 407 x a2 -8 4 53
g2 408 x a2 0 6 52.8
真实情节的布局
grid(r = 3, n = 3)
gene/region x y z
gene1
gene2
gene3
I have a dataset that contains multiple groups and exp. conditions. (here represents as group <- c("g1", "g2")
and con <- c("A1", "A2", "B1", "B2")
) I made a 3x3 plot matrix, and below is a part of one of the plots. a1 in the graph is just a derivative con of A1 and do not need to have a separate background than A1.
What I want is give them different colour background and frames so they are more friendly to readers. (e.g. the following output but fill the entire plating area [colour filled background distinguishing condition A, B, while coloured border differentiates condition 1, 2]) How could I archive this in R?
---- Update ----
As you commented, Here is a demo data that preserves the structure of the original data frame.
(sep = " ")# I use csv in real data,
# here is just for better presentation
group animal_nr region con gene1 gene2 gene3
g1 101 x A1 10 15 100
g1 102 x A1 12 15 110
g1 103 x A1 9 16 90
g1 104 x A1 11 14 105
g1 201 x a1 10 15 100
g1 202 x a1 12 16 110
g1 203 x a1 9 16 90
g1 204 x a1 11 14 105
g1 105 x A2 -8 5 50
g1 106 x A2 -9 5.5 52
g1 107 x A2 -8 4 53
g1 108 x A2 0 6 52.8
g1 205 x a2 -8 5 50
g1 206 x a2 -9 5.5 52
g1 207 x a2 -8 4 53
g1 208 x a2 0 6 52.8
g1 109 x B1 2 15 29
g1 110 x B1 3 15.5 35
g1 111 x B1 1 16 33
g1 112 x B1 1.1 14 30
g1 209 x b1 2 15 29
g1 210 x b1 3 15.5 35
g1 211 x b1 1 16 33
g1 212 x b1 1.1 14 30
g1 113 x B2 -10 2 10
g1 114 x B2 -8 3 11
g1 115 x B2 -9 2 11.1
g1 116 x B2 -11 4 12
g2 301 x A1 10 15 100
g2 302 x A1 12 15 110
g2 303 x A1 9 16 90
g2 304 x A1 11 14 105
g2 401 x a1 10 15 100
g2 402 x a1 12 16 110
g2 403 x a1 9 16 90
g2 404 x a1 11 14 105
g2 305 x A2 -8 5 50
g2 306 x A2 -9 5.5 52
g2 307 x A2 -8 4 53
g2 308 x A2 0 6 52.8
g2 405 x a2 -8 5 50
g2 406 x a2 -9 5.5 52
g2 407 x a2 -8 4 53
g2 408 x a2 0 6 52.8
Layout of real plot
grid(r = 3, n = 3)
gene/region x y z
gene1
gene2
gene3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常,您可以使用
geom_Rect
添加一些背景矩形。但是,这需要一些数据争吵才能获取Xmin
和xmax
值。基本上,这涉及设置数据框并将您的类别转换为数字位置。同样,在此阶段,我们还添加了一些可以在fill
和color
上映射的列,以实现您所需的结果。请注意,我将RECT大小稍微降低到width_Rect = .98
以防止大纲重叠。编辑而不是使用
substr
您当然可以使用ifelse
或...将类别分配给填充和颜色:In general you could add some background rectangles using
geom_rect
. which however requires some data wrangling to get thexmin
andxmax
values. Basically this involves setting up a dataframe and converting your categories to numeric positions. Also at this stage we also add some columns which could be mapped onfill
andcolor
to achieve your desired result. Note that I slightly reduced the rect size towidth_rect = .98
to prevent the outlines from overlapping.EDIT Instead of using
substr
you could of course use anifelse
or ... to assign the categories to fill and color:在这里,您有一个带有虚拟数据的示例,并使用
geom_rec
您可以选择要用某种颜色填充的背景的那一部分,更改xmin
和xmax < /代码>。
输出:

Here you have an example with dummy data and using
geom_rec
you can select that part of the background that you want to fill with some color, changingxmin
andxmax
.OUTPUT:
