带有3个变量的barplot(连续的X和Y以及第三个堆栈变量) [英] barplot with 3 variables (continous X and Y and third stacked variable)
本文介绍了带有3个变量的barplot(连续的X和Y以及第三个堆栈变量)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
myd< - structure(list(var1 = structure(1:4, .Label = c(II,III,
IV,V),class =factor),zero_co = c(15.15152,3.030303,
0,0), non_zero_CO = c(84.84848,96.969697,100,100),size = c(230,
813,317,1532)),.Names = c(var1,zero_co,non_zero_CO,
size),row.names = c(NA,-4L),class =data.frame)
#myd
#I II III IV V
#zero_co 15.15152 3.030303 0 0
#非零CO 84.84848 96.969697 100 100
#size 230.00000 813.000000 317 1532
我想在y轴和其他两个变量 zero_co
上绘制 size
和非零CO
作为x轴上的堆叠条。我正在尝试使用 gplots
和 ggplots
来绘制此图,但发现有困难。如何绘制这个?
解决方案
如果我理解正确,这是一个解决方案。由于您在x轴和y轴都有定量变量,因此您无法使用条形图。
myd < - data.frame(var1 = c(II ,III,IV,V),zero_co = c(15.15152,3.030303,0,0),
non_zero_CO = c(84.84848,96.969697,100,100),
size = c(230.00000,813.000000,317,1532))
require(ggplot2)
ggplot(myd)+ geom_rect(aes(xmin = 0,xmax = zero_co,ymin (xmin = zero_co,xmax = zero_co + non_zero_CO,ymin = size,ymax = size + 80),fill =darkblue(size = 80),fill =lightgreen)+
geom_rect )+ theme_bw()
给出你的情节:
I have some data like this:
myd <- structure(list(var1 = structure(1:4, .Label = c("II", "III",
"IV", "V"), class = "factor"), zero_co = c(15.15152, 3.030303,
0, 0), non_zero_CO = c(84.84848, 96.969697, 100, 100), size = c(230,
813, 317, 1532)), .Names = c("var1", "zero_co", "non_zero_CO",
"size"), row.names = c(NA, -4L), class = "data.frame")
# myd
# I II III IV V
# zero_co 15.15152 3.030303 0 0
# non-zero CO 84.84848 96.969697 100 100
# size 230.00000 813.000000 317 1532
I want to plot size
on the y-axis and other two variables zero_co
and non-zero CO
as a stacked bars on the x-axis. I am trying to plot this using gplots
and ggplots
but finding difficulties. How do I plot this?
解决方案
Here is a solution if I understand it correctly. As you have quantative variable at both x and y axis you can not do with bar plot. You need to use rectangle (look like bar anyway).
myd <- data.frame (var1 = c("II", "III", "IV", "V"), zero_co = c(15.15152 , 3.030303, 0, 0),
non_zero_CO = c(84.84848, 96.969697, 100, 100),
size = c(230.00000, 813.000000, 317, 1532))
require(ggplot2)
ggplot(myd) + geom_rect(aes(xmin = 0, xmax = zero_co, ymin =size , ymax =size + 80 ), fill = "lightgreen") +
geom_rect(aes(xmin = zero_co, xmax = zero_co + non_zero_CO, ymin =size , ymax =size + 80 ), fill = "darkblue") + theme_bw()
Give you the plot:
这篇关于带有3个变量的barplot(连续的X和Y以及第三个堆栈变量)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文