尝试将 ggplot 图迁移到 0.9.3 版,下面代码中注释掉的行会产生Discrete value supplied to continuous scale
错误(以前不是问题)。你能帮我改正吗?
如果您需要数据进行实验,我在下面提供。
ggplot(mdfr, aes(as.Date(value, "%d/%m/%Y"), name, colour = factor(stadio))) +
geom_line(aes(size=rating)) +
labs(colour="Baseline/Actual :", x = "", y = "") +
scale_colour_brewer(palette="BrBG",breaks = c("1", "3", "6","8"),
labels = c("Label 1", "Label 2", "Label 3","Label 4")) +
scale_size_manual(breaks = levels(mdfr$rating), values = as.integer(levels(mdfr$rating)), guide = "none") +
theme_bw() +
#geom_vline(data=dfrDataDate, aes(xintercept= as.Date(data.date, "%Y-%m-%d")),colour=rgb(215, 25, 28, max = 255),size=1) +
geom_text(data=dfrDataDate, aes(x= as.Date(data.date, "%Y-%m-%d"), label = format(as.Date(data.date),"%d/%m/%Y")), hjust = -0.05, vjust = 1.5, colour = "darkred", size = 3 ) +
geom_text(data=dfrLabels, aes(x= as.Date(diag_date, "%d/%m/%Y"), label = format(as.Date(diag_date, "%d/%m/%Y"),"%d/%m/%Y")), hjust = 0.5, vjust = -1, colour = "black", size = 3 ) +
geom_text(data=dfrYpogr, aes(x= as.Date(ypogr_date, "%d/%m/%Y"), label = format(as.Date(ypogr_date, "%d/%m/%Y"),"%d/%m/%Y")), hjust = 0.5, vjust = -1, colour = "black", size = 3 ) +
scale_y_discrete(breaks=names, labels=new.names) +
ggtitle('New plot title') +
theme(plot.title = element_text(size=16),
legend.position = "top",
legend.title = element_text(size=12),
legend.text = element_text(size=10),
legend.key = element_rect(colour='white'),
axis.text.x = element_text(angle=0,size = 10),
axis.title.x = element_text(size=14),
axis.text.y = element_text(size=10),
axis.title.y = element_text(angle=90,size=14),
axis.ticks.length = unit(.05, "cm")
)
生成图表所需的数据:
mdfr <- structure(list(name = structure(c(22L, 22L, 22L, 22L, 20L, 20L,
20L, 20L, 18L, 18L, 18L, 18L, 16L, 16L, 16L, 16L, 14L, 14L, 14L,
14L, 12L, 12L, 12L, 12L, 10L, 10L, 10L, 10L, 8L, 8L, 8L, 8L,
6L, 6L, 6L, 6L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 21L, 21L, 21L,
21L, 19L, 19L, 19L, 19L, 17L, 17L, 17L, 17L, 15L, 15L, 15L, 15L,
13L, 13L, 13L, 13L, 11L, 11L, 11L, 11L, 9L, 9L, 9L, 9L, 7L, 7L,
7L, 7L, 5L, 5L, 5L, 5L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 22L,
22L, 22L, 22L, 20L, 20L, 20L, 20L, 18L, 18L, 18L, 18L, 16L, 16L,
16L, 16L, 14L, 14L, 14L, 14L, 12L, 12L, 12L, 12L, 10L, 10L, 10L,
10L, 8L, 8L, 8L, 8L, 6L, 6L, 6L, 6L, 4L, 4L, 4L, 4L, 2L, 2L,
2L, 2L, 21L, 21L, 21L, 21L, 19L, 19L, 19L, 19L, 17L, 17L, 17L,
17L, 15L, 15L, 15L, 15L, 13L, 13L, 13L, 13L, 11L, 11L, 11L, 11L,
9L, 9L, 9L, 9L, 7L, 7L, 7L, 7L, 5L, 5L, 5L, 5L, 3L, 3L, 3L, 3L,
1L, 1L, 1L, 1L), .Label = c("733 A", "733 B", "725 A", "725 B",
"727 A", "727 B", "558 A", "558 B", "705 A", "705 B", "635 A",
"635 B", "737 A", "737 B", "719 A", "719 B", "700 A", "700 B",
"579 A", "579 B", "541 A", "541 B"), class = "factor"), stadio = c(2,
4, 5, 7, 2, 4, 5, 7, 2, 4, 5, 7, 2, 4, 5, 7, 2, 4, 5, 7, 2, 4,
5, 7, 2, 4, 5, 7, 2, 4, 5, 7, 2, 4, 5, 7, 2, 4, 5, 7, 2, 4, 5,
7, 1, 3, 6, 8, 1, 3, 6, 8, 1, 3, 6, 8, 1, 3, 6, 8, 1, 3, 6, 8,
1, 3, 6, 8, 1, 3, 6, 8, 1, 3, 6, 8, 1, 3, 6, 8, 1, 3, 6, 8, 1,
3, 6, 8, 2, 4, 5, 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38L, 7L, 7L, 7L, 31L, 9L, 15L, 27L, 34L,
4L, 19L, 21L, 37L, 1L, 9L, 23L, 33L, 8L, 13L, 25L, 32L, 10L,
16L, 28L, 29L, 5L, 12L, 26L, 35L, 6L, 17L, 22L, 39L, 11L, 17L,
22L, 30L, 3L, 18L, 20L, 36L, 2L, 14L, 24L, 31L, 50L, 50L, 50L,
56L, 15L, 52L, 55L, 32L, 48L, 49L, 55L, 34L, 1L, 53L, 53L, 57L,
49L, 51L, 54L, 58L, 10L, 16L, 28L, 29L, 5L, 12L, 26L, 35L, 6L,
17L, 22L, 39L, 11L, 17L, 22L, 30L, 18L, 20L, 36L, 45L, 14L, 24L,
38L, 46L, 7L, 7L, 31L, 42L, 15L, 27L, 34L, 44L, 19L, 21L, 37L,
44L, 9L, 23L, 33L, 40L, 13L, 25L, 32L, 44L, 16L, 28L, 29L, 41L,
12L, 26L, 35L, 43L, 17L, 22L, 39L, 47L, 17L, 22L, 30L, 47L, 18L,
20L, 36L, 59L, 14L, 24L, 31L, 64L, 50L, 50L, 56L, 66L, 52L, 55L,
32L, 61L, 49L, 55L, 34L, 63L, 53L, 53L, 57L, 65L, 51L, 54L, 58L,
60L, 16L, 28L, 29L, 63L, 12L, 26L, 35L, 62L, 17L, 22L, 39L, 67L,
17L, 22L, 30L, 61L), .Label = c("03/05/2012", "07/06/2011", "22/02/2011",
"22/06/2012", "23/12/2011", "28/12/2011", "29/02/2012", "29/03/2012",
"29/06/2012", "30/05/2011", "30/12/2011", "03/02/2012", "04/07/2012",
"08/02/2012", "10/07/2012", "17/10/2011", "23/02/2012", "24/05/2011",
"25/07/2012", "01/06/2011", "01/08/2012", "02/03/2012", "05/07/2012",
"09/02/2012", "12/07/2012", "16/02/2012", "19/07/2012", "27/01/2012",
"06/04/2012", "07/06/2012", "08/05/2012", "09/10/2012", "11/09/2012",
"16/10/2012", "18/05/2012", "20/09/2011", "23/10/2012", "24/04/2012",
"31/05/2012", "04/02/2013", "09/09/2012", "12/11/2012", "19/11/2012",
"28/02/2013", "28/09/2012", "29/10/2012", "30/11/2012", "01/07/2012",
"06/07/2012", "22/03/2012", "02/08/2012", "17/07/2012", "31/07/2012",
"06/09/2012", "26/07/2012", "12/06/2012", "13/11/2012", "20/11/2012",
"17/01/2013", "21/05/2013", "21/12/2012", "22/07/2012", "28/12/2012",
"30/03/2013", "30/04/2013", "31/01/2013", "31/12/2012"), class = "factor"),
rating = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L), .Label = c("3", "5"), class = "factor")), row.names = c(NA,
-176L), .Names = c("name", "stadio", "variable", "value", "rating"
), class = "data.frame")
dfrDataDate <- structure(list(name = structure(1L, .Label = "733 A", class = "factor"),
data.date = structure(1L, .Label = "2013-01-02", class = "factor")), .Names = c("name",
"data.date"), row.names = c(NA, -1L), class = "data.frame")
dfrLabels <- structure(list(name = c("541 A", "579 A", "700 A", "719 A", "737 A",
"635 A", "705 A", "558 A", "727 A", "725 A", "733 A"), diag_date = c("20/09/2011",
"08/05/2012", "12/06/2012", "09/10/2012", "16/10/2012", "13/11/2012",
"20/11/2012", "06/04/2012", "18/05/2012", "31/05/2012", "07/06/2012"
)), .Names = c("name", "diag_date"), row.names = c(135L, 139L,
143L, 147L, 151L, 155L, 159L, 163L, 167L, 171L, 175L), class = "data.frame")
dfrYpogr <- structure(list(name = c("541 A", "579 A", "700 A", "719 A", "737 A",
"635 A", "705 A", "558 A", "727 A", "725 A", "733 A"), ypogr_date = c("17/01/2013",
"30/03/2013", "31/01/2013", "21/12/2012", "28/12/2012", "30/04/2013",
"21/05/2013", "28/12/2012", "22/07/2012", "31/12/2012", "21/12/2012"
)), .Names = c("name", "ypogr_date"), row.names = c(136L, 140L,
144L, 148L, 152L, 156L, 160L, 164L, 168L, 172L, 176L), class = "data.frame")
names <- as.character(unique(mdfr$name))
new.names <- c("No.541", "No.579", "No.700", "No.719", "No.737", "No.635",
"No.705", "No.558", "No.727", "No.725", "No.733", "", "",
"", "", "", "", "", "", "", "", "")