我有这个代码来绘制一些图表
library(grid);
library(ggplot2);
library(reshape2);
pdf(file = '$filename.pdf', width=5, height=6.7);
dat <- read.csv('bdr.csv');
ggplot(dat, aes(x = Experiment, y = Mean, colour = Method:factor(Values),
linetype = Method:factor(Values), shape = Method:factor(Values))) +
geom_line() +
geom_point()+
labs(x='$xlabel',y='$ylabel', fill='') +
scale_shape_manual(name = 'Method and\nBeacon Send Rate',
labels = c('DTB-MAC, Beacon Send Rate:1HZ', 'DTB_MAC, Beacon Send Rate:5HZ', 'DTB_MAC, Beacon Send Rate:10HZ', 'IEEE802.11P, Beacon Send Rate:1HZ', 'IEEE802.11P, Beacon Send Rate:5HZ', 'IEEE802.11P, Beacon Send Rate:10HZ'),
values = rep(c(15,16,17), 2)) +
scale_linetype_manual(name='Method and\nBeacon Send Rate',
labels = c('DTB-MAC, Beacon Send Rate:1HZ', 'DTB_MAC, Beacon Send Rate:5HZ', 'DTB_MAC, Beacon Send Rate:10HZ', 'IEEE802.11P, Beacon Send Rate:1HZ', 'IEEE802.11P, Beacon Send Rate:5HZ', 'IEEE802.11P, Beacon Send Rate:10HZ'),
values = rep(c('solid', 'dashed', 'dotted'), 2)) +
scale_color_manual(name='Method and\nBeacon Send Rate',
labels = c('DTB-MAC, Beacon Send Rate:1HZ', 'DTB_MAC, Beacon Send Rate:5HZ', 'DTB_MAC, Beacon Send Rate:10HZ', 'IEEE802.11P, Beacon Send Rate:1HZ', 'IEEE802.11P, Beacon Send Rate:5HZ', 'IEEE802.11P, Beacon Send Rate:10HZ'),
values = rep(c('red', 'deepskyblue'), each = 3)) +
scale_y_continuous(limits = c(0, 100), breaks = (seq(0,100,by = 20))) +
scale_x_continuous(breaks = c(10, 20, 40, 60, 80)) +
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.direction='vertical',
legend.key = element_blank(),
legend.position='bottom',
legend.background = element_rect(colour = 'black'),
legend.title=element_blank());
这是结果
但是如何减少图例的大小并将项目分成两列以避免变大?