如何将堆积的条形图上的图例移到侧面?

时间:2014-06-09 01:40:00

标签: r plot ggplot2

我正在制作带有R的堆积条形图。

# initialize a data frame
df_values_2012  <- data.frame(
   workvalue = character (  )
,  most     = numeric (  ) 
,  second   = numeric (  )
,  third    = numeric (  )
,  fourth   = numeric (  )
,  fifth    = numeric (  )
,  stringsAsFactors=FALSE
   )

df_values_2012 [1 , ] <-
c (  "value01" ,
 7L, 25L, 46L, 17L, 5L)


df_values_2012 [2 , ] <-
c (  "value02" ,
 15L,  29L, 21L, 21L, 14L)


df_values_2012 [3 , ] <-
c (  "value03" ,
27L, 8L, 7L,  12L, 46L )

df_values_2012 [4 , ] <-
c (  "value04" ,
 28L, 16L, 13L, 26L, 17L )

df_values_2012 [5 , ] <-
c (  "value05" ,
23L, 22L,  13L, 25L, 17L  )`

df_values_2012

  workvalue most second third fourth fifth
1   value01    7     25    46     17     5
2   value02   15     29    21     21    14
3   value03   27      8     7     12    46
4   value04   28     16    13     26    17
5   value05   23     22    13     25    17

你会注意到 - 两行 - 行和列总计为100。

我一直在制作结果图表。 但是,我在传说中遇到了麻烦。


barplot ( as.matrix  (  df_values_2012 [ , 2:6 ] )
, col=c("blue", "green", "red", "yellow", "cyan")
 )

barplot ( as.matrix (  df_values_2012  [ , 2:6 ] )
, col=c("blue", "green", "red", "yellow", "cyan")
, legend.text = df_values_2012  [ , 1]
)

barplot ( as.matrix (  df_values_2012  [ , 2:6 ] )
, col=c("blue", "green", "red", "yellow", "cyan")
, legend.text = df_values_2012  [ , 1]
, args.legend = "topleft"
)

图例位于图表的顶部。 很难说出来。

有没有办法将传奇放在一边? 也许,通过使用mosaicplot或ggplot?

到目前为止我所尝试的并没有成功。 浏览文档需要很长时间。

非常感谢!

0 个答案:

没有答案
相关问题