比较R中不同值的两个协议

时间:2014-09-23 16:24:37

标签: r

我有这个数据集:

Experiment,Method,Values,Mean
10,IEEE802.11P,1,1
10,IEEE802.11P,5,2
10,IEEE802.11P,10,3
20,IEEE802.11P,1,4
20,IEEE802.11P,5,5
20,IEEE802.11P,10,6
40,IEEE802.11P,1,7
40,IEEE802.11P,5,8
40,IEEE802.11P,10,9
60,IEEE802.11P,1,10
60,IEEE802.11P,5,11
60,IEEE802.11P,10,12
80,IEEE802.11P,1,13
80,IEEE802.11P,5,14
80,IEEE802.11P,10,15
10,DTB-MAC,1,16
10,DTB-MAC,5,17
10,DTB-MAC,10,18
20,DTB-MAC,1,19
20,DTB-MAC,5,20
20,DTB-MAC,10,21
40,DTB-MAC,1,22
40,DTB-MAC,5,23
40,DTB-MAC,10,24
60,DTB-MAC,1,25
60,DTB-MAC,5,26
60,DTB-MAC,10,27
80,DTB-MAC,1,28
80,DTB-MAC,5,29
80,DTB-MAC,10,30

我实际上想要在不同的情况下(10,20,40,60,80)比较IEEE802.11PDTB-MAC不同的值(1,5,10)并将图形全部合二为一

知道怎么用R画它? 我想将实验分配给x轴,并指向y轴。并将所有这些信息混合在一个图表中。

我尝试了如下:

library(grid);
library(ggplot2);
library(reshape2);
pdf(file = '$filename.pdf', width=5, height=5);

dat <- read.csv('bdr.csv');

dat1 <- melt(dat,id.vars = c('Experiment','Method'));

ggplot(dat1,aes(factor(Experiment),value,fill=factor(variable)))+geom_line()+
      facet_grid(. ~ Method)+
      labs(x='$xlabel',y='$ylabel', fill='')+
    scale_fill_manual(values = c('red','lawngreen','deepskyblue'), labels = c('Values', 'Mean')) +
scale_y_continuous(limits = c(0, 100), breaks = (seq(0,100,by = 5)))+
theme_bw()+
      theme(    panel.grid.major = element_line(colour = 'grey'),
    panel.border = element_rect(colour = 'black'),
axis.line = element_blank(),
    panel.background = element_blank(), legend.position='top', legend.direction='horizontal', panel.margin = unit(1, 'lines'),legend.background = element_rect(colour = 'grey'));

1 个答案:

答案 0 :(得分:1)

library(ggplot2)
ggplot(dat, aes(x = Experiment, y = Mean, colour = Method,
                linetype = as.factor(Values), shape = as.factor(Values))) +
  geom_line() +
  geom_point()

其中dat是数据框的名称。 enter image description here