1
Основываясь на приведенном ниже коде, я успешно рисовал линейный график в R. Но я хотел бы иметь рамку вокруг моей фигуры.Как создать рамку линейного участка в ggplot2
# To load the packages
library(ggplot2)
library(reshape2)
# my data
dat<-structure(list(B50K = c(0.3795, 0.3178, 0.2795, 0.2417, 0.2002, 0.1642),
B50K.1000C50K = c(0.4192, 0.3758, 0.3266, 0.2599, 0.2287, 0.1911),
B50K.2000C50K = c(0.4675, 0.4249, 0.3763, 0.2898, 0.2531, 0.2151),
B50K.4000C50K = c(0.5357, 0.501, 0.4636, 0.3291, 0.2962, 0.2544),
B50K.8000C50K = c(0.6217, 0.587, 0.5583, 0.3736, 0.3485, 0.2951),
TimestepTrait = structure(c(2L, 5L, 6L, 1L, 3L, 4L),
.Label = c("T18-Fertility", "T18-Yield", "T19-Fertility", "T20-Fertility", "T19-Yield","T20-Yield"),
class = "factor")), .Names = c("B-50K", "B-50K+1000 C-50K", "B-50K+2000 C-50K",
"B-50K+4000 C-50K", "B-50K+8000 C-50K", "TimestepTrait"), row.names = c(NA,
-6L), class = "data.frame")
# assume xaxile column is unneeded
dat$xaxile <- NULL
# reshape data for plotting
dat.m <- melt(dat)
dat.m$TimestepTrait <- factor(dat.m$TimestepTrait, levels=unique(dat$TimestepTrait), labels=unique(dat$TimestepTrait))
# plot
da<- ggplot(dat.m, aes(x=variable, y=value, colour=TimestepTrait, col= TimestepTrait,
shape=TimestepTrait, linetype=TimestepTrait, group=TimestepTrait)) +
geom_point(size=4) +
geom_line(lwd=1.2) +
# theme_bw() +
# theme(panel.grid.major = element_line(colour = "#808080")) +
theme(axis.text.x = element_text(angle = 00, hjust = 1, size=11, color="darkred")) +
theme(axis.text.y = element_text(angle = 90, vjust = 1, size=13, color="darkred")) +
theme(axis.title.y = element_text(size = rel(1.4), angle = 90)) +
theme(axis.title.x = element_text(size = rel(1.2), angle = 00)) +
theme(legend.text=element_text(size=14)) +
# theme(plot.legend = element_text(lineheight=3, face="bold", color="black", size=29)) +
ylim(0.0, 0.7) +
scale_linetype_manual(values = c(rep("solid", 3), rep("dashed", 3)))
davk<-da + xlab("Reference Population Size") + ylab("Reliability (GEBV,TBV)")# + ggtitle("Davood")
ggsave("Figure 1.jpg", plot = davk, scale=2, width = 6, height = 4, dpi=500)
Кстати, а может быть, вы можете увидеть после запуска ниже коды R, значение оси х и у отклонилось от их правильной позиции. Как это исправить?
Любая помощь будет оценена заранее!
Спасибо lukeA. Он работал очень хорошо. Кроме того, мое название легенды - «TimestepTrait». как мы можем изменить его на «Timestep-Trait»? – user1677032
Вы можете добавить '+ labs (color =" Timestep-Trait ")', а также добавить '+ guide (shape = FALSE, linetype = FALSE)'. – lukeA
Дорогой lukeA, это (labs (color = "Timestep-Trait") + руководства (shape = FALSE, linetype = FALSE)) работает, но шаблон легенды для всех шести сценариев под заголовком легенды одинаковый! Есть ли для этого решение? – user1677032