0

我正在尝试绘制显示在两种情况下由颜色指示的值变化的图表。我在论坛上看了几个帖子,但无法完全弄清楚。到目前为止我尝试过的一些方法

ggplot(regime_shift_part1, aes(x = TStep, y = KgBiomass, **colour=factor(Ecoregion)**)) + 
 geom_point(size=2.2)+
 scale_x_discrete(name="Time Step", breaks=(0:6)*50, labels=c("2000", "2050", "2100", "2150", "2200", "2250", "2300"))+
 labs(title="Maximum Biomass Producing Region") + 
 theme(text = element_text(size=12),axis.text.x = element_text(vjust=1))+
 scale_y_continuous(name=expression(paste("Maximum Biomass (Kg m"^"-2",")")))+
 geom_line(data=regime_shift_part1, aes(x=TStep, y=KgBiomass, lty=factor(Scenario)))+
 facet_wrap(~Species)

这段代码完成了我想要的部分工作,但是当它从一组更改为另一组时,线路会断开连接。例如,在“abiebals”中看到蓝色和绿色之间的差距,在“Acerrubr”中看到绿色和橙色之间的差距等等。

“对不起,我不能发布图片,所以你可能必须使用代码来显示”

我需要线条流畅。所以,我尝试了另一种方法。我在代码中所做的唯一编辑以粗体突出显示。编辑后的代码现在如下所示:

ggplot(regime_shift_part1, aes(x = TStep, y = KgBiomass)) + 
 **geom_point(aes(color = factor(Ecoregion)**), size=2.2)+
 scale_x_discrete(name="Time Step", breaks=(0:6)*50, labels=c("2000", "2050", "2100", "2150", "2200", "2250", "2300"))+
 labs(title="Maximum Biomass Producing Region") + 
 theme(text = element_text(size=12),axis.text.x = element_text(vjust=1))+
 scale_y_continuous(name=expression(paste("Maximum Biomass (Kg m"^"-2",")")))+
 geom_line(data=regime_shift_part1, aes(x=TStep, y=KgBiomass, lty=factor(Scenario)))+
 facet_wrap(~Species)

“请使用代码查看图像。我无法发布它”

此代码使线条连续,但线条颜色现在为黑色。如果您能提出用不同颜色使线条连续的方法,我将不胜感激。另外,我想手动为不同的生态区分配颜色。很难区分生态区 6-7、8-9、13-14。我尝试了几种方法,但都没有奏效。

我的数据是:

dput(regime_shift_part1)
structure(list(Ecoregion = c(9L, 9L, 13L, 13L, 9L, 13L, 9L, 9L, 
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 
6L, 6L, 6L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 
11L, 11L, 11L, 11L, 11L, 11L, 7L, 11L, 7L, 12L, 12L, 12L, 12L, 
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 6L, 6L, 6L, 
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 
6L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 9L, 
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 13L, 
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 
8L, 8L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 
14L, 14L, 14L, 14L, 14L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 
12L, 12L, 12L, 12L, 12L, 12L, 12L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 8L, 8L, 8L, 14L, 14L, 14L, 14L, 
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 12L, 12L, 12L, 12L, 12L, 
12L, 5L, 5L, 5L, 8L, 8L, 8L, 8L, 14L, 14L, 14L, 14L, 8L, 8L, 
8L, 8L, 7L, 7L, 7L, 9L, 8L, 8L, 8L, 8L, 8L, 8L, 13L, 13L, 13L, 
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 
13L, 13L, 6L, 6L, 6L, 6L, 6L, 6L, 14L, 14L, 14L, 14L, 14L, 14L, 
14L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 3L, 3L, 3L, 3L, 3L, 3L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 13L, 
13L, 13L, 13L, 13L, 2L, 2L, 1L, 14L, 14L, 14L, 14L, 14L, 14L, 
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 8L, 8L, 
8L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L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 6L, 6L, 6L, 6L, 
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 
7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 
8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 
9L, 9L, 9L, 9L, 9L), .Label = c("abiebals", "acerrubr", "acersacc", 
"betualle", "betupapy", "carycord", "fagugran", "fraxamer", "fraxnigr", 
"fraxpenn", "piceglau", "picemari", "pinubank", "pinuresi", "pinustro", 
"popubals", "popugran", "poputrem", "prunsero", "queralba", "querelli", 
"quermacr", "querrubr", "quervelu", "thujocci", "tiliamer", "tsugcana"
), class = "factor"), TStep = c(0L, 10L, 20L, 30L, 40L, 50L, 
60L, 70L, 80L, 90L, 100L, 110L, 120L, 130L, 140L, 150L, 160L, 
170L, 180L, 190L, 200L, 210L, 220L, 230L, 240L, 250L, 260L, 270L, 
280L, 290L, 300L, 0L, 10L, 20L, 30L, 40L, 50L, 60L, 70L, 80L, 
90L, 100L, 110L, 120L, 130L, 140L, 150L, 160L, 170L, 180L, 190L, 
200L, 210L, 220L, 230L, 240L, 250L, 260L, 270L, 280L, 290L, 300L, 
0L, 10L, 20L, 30L, 40L, 50L, 60L, 70L, 80L, 90L, 100L, 110L, 
120L, 130L, 140L, 150L, 160L, 170L, 180L, 190L, 200L, 210L, 220L, 
230L, 240L, 250L, 260L, 270L, 280L, 290L, 300L, 0L, 10L, 20L, 
30L, 40L, 50L, 60L, 70L, 80L, 90L, 100L, 110L, 120L, 130L, 140L, 
150L, 160L, 170L, 180L, 190L, 200L, 210L, 220L, 230L, 240L, 250L, 
260L, 270L, 280L, 290L, 300L, 0L, 10L, 20L, 30L, 40L, 50L, 60L, 
70L, 80L, 90L, 100L, 110L, 120L, 130L, 140L, 150L, 160L, 170L, 
180L, 190L, 200L, 210L, 220L, 230L, 240L, 250L, 260L, 270L, 280L, 
290L, 300L, 0L, 10L, 20L, 30L, 40L, 50L, 60L, 70L, 80L, 90L, 
100L, 110L, 120L, 130L, 140L, 150L, 160L, 170L, 180L, 190L, 200L, 
210L, 220L, 230L, 240L, 250L, 260L, 270L, 280L, 290L, 300L, 0L, 
10L, 20L, 30L, 40L, 50L, 60L, 70L, 80L, 90L, 100L, 110L, 120L, 
130L, 140L, 150L, 160L, 170L, 180L, 190L, 200L, 210L, 220L, 230L, 
240L, 250L, 260L, 270L, 280L, 290L, 300L, 0L, 10L, 20L, 30L, 
40L, 50L, 60L, 70L, 80L, 90L, 100L, 110L, 120L, 130L, 140L, 150L, 
160L, 170L, 180L, 190L, 200L, 210L, 220L, 230L, 240L, 250L, 260L, 
270L, 280L, 290L, 300L, 0L, 10L, 20L, 30L, 40L, 50L, 60L, 70L, 
80L, 90L, 100L, 110L, 120L, 130L, 140L, 150L, 160L, 170L, 180L, 
190L, 200L, 210L, 220L, 230L, 240L, 250L, 260L, 270L, 280L, 290L, 
300L, 0L, 10L, 20L, 30L, 40L, 50L, 60L, 70L, 80L, 90L, 100L, 
110L, 120L, 130L, 140L, 150L, 160L, 170L, 180L, 190L, 200L, 210L, 
220L, 230L, 240L, 250L, 260L, 270L, 280L, 290L, 300L, 0L, 10L, 
20L, 30L, 40L, 50L, 60L, 70L, 80L, 90L, 100L, 110L, 120L, 130L, 
140L, 150L, 160L, 170L, 180L, 190L, 200L, 210L, 220L, 230L, 240L, 
250L, 260L, 270L, 280L, 290L, 300L, 0L, 10L, 20L, 30L, 40L, 50L, 
60L, 70L, 80L, 90L, 100L, 110L, 120L, 130L, 140L, 150L, 160L, 
170L, 180L, 190L, 200L, 210L, 220L, 230L, 240L, 250L, 260L, 270L, 
280L, 290L, 300L, 0L, 10L, 20L, 30L, 40L, 50L, 60L, 70L, 80L, 
90L, 100L, 110L, 120L, 130L, 140L, 150L, 160L, 170L, 180L, 190L, 
200L, 210L, 220L, 230L, 240L, 250L, 260L, 270L, 280L, 290L, 300L, 
0L, 10L, 20L, 30L, 40L, 50L, 60L, 70L, 80L, 90L, 100L, 110L, 
120L, 130L, 140L, 150L, 160L, 170L, 180L, 190L, 200L, 210L, 220L, 
230L, 240L, 250L, 260L, 270L, 280L, 290L, 300L, 0L, 10L, 20L, 
30L, 40L, 50L, 60L, 70L, 80L, 90L, 100L, 110L, 120L, 130L, 140L, 
150L, 160L, 170L, 180L, 190L, 200L, 210L, 220L, 230L, 240L, 250L, 
260L, 270L, 280L, 290L, 300L, 0L, 10L, 20L, 30L, 40L, 50L, 60L, 
70L, 80L, 90L, 100L, 110L, 120L, 130L, 140L, 150L, 160L, 170L, 
180L, 190L, 200L, 210L, 220L, 230L, 240L, 250L, 260L, 270L, 280L, 
290L, 300L, 0L, 10L, 20L, 30L, 40L, 50L, 60L, 70L, 80L, 90L, 
100L, 110L, 120L, 130L, 140L, 150L, 160L, 170L, 180L, 190L, 200L, 
210L, 220L, 230L, 240L, 250L, 260L, 270L, 280L, 290L, 300L, 0L, 
10L, 20L, 30L, 40L, 50L, 60L, 70L, 80L, 90L, 100L, 110L, 120L, 
130L, 140L, 150L, 160L, 170L, 180L, 190L, 200L, 210L, 220L, 230L, 
240L, 250L, 260L, 270L, 280L, 290L, 300L), Spnum = c(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,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 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, 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), .Label = c("BAU", 
"GFDL_A1fi"), class = "factor"), KgBiomass = c(1.5531, 1.7151, 
1.8749, 2.0402, 2.2104, 2.379, 2.6025, 2.8299, 3.1307, 3.5236, 
3.9801, 4.6243, 5.2637, 6.0671, 6.9228, 7.6249, 8.3212, 8.7372, 
9.0633, 9.3077, 9.3587, 9.3707, 9.3207, 9.211, 9.2828, 9.3028, 
9.3942, 9.2435, 9.1243, 9.2784, 9.2439, 5.0689, 5.0771, 5.09, 
4.9926, 4.8535, 4.8401, 4.717, 4.573, 4.2985, 3.9545, 3.5446, 
3.0536, 2.7713, 2.5378, 2.2779, 2.0237, 1.7753, 1.578, 1.4553, 
1.3934, 1.381, 1.3822, 1.392, 1.4187, 1.4356, 1.4571, 1.4912, 
1.4921, 1.4781, 1.3755, 1.31, 9.218, 9.4652, 9.4584, 9.5645, 
9.773, 9.9784, 9.8208, 9.8178, 10.1043, 10.293, 10.8209, 11.3321, 
11.7042, 12.2588, 12.9198, 13.288, 14.036, 14.9031, 15.725, 16.1998, 
16.6214, 16.9101, 17.1422, 17.2767, 17.4555, 17.6199, 17.5614, 
17.7563, 17.6413, 17.7908, 17.8249, 2.4078, 2.3768, 2.371, 2.3227, 
2.2606, 2.2555, 2.1939, 2.1402, 2.0406, 1.9384, 1.8373, 1.7111, 
1.5859, 1.4751, 1.4032, 1.327, 1.2602, 1.1885, 1.1452, 1.1336, 
1.1565, 1.2179, 1.3024, 1.3954, 1.4924, 1.572, 1.6506, 1.7287, 
1.8076, 1.871, 1.8792, 2.0129, 2.1072, 2.2432, 2.3797, 2.4395, 
2.4376, 2.4098, 2.3166, 2.1962, 2.0202, 1.8732, 1.6444, 1.4815, 
1.2857, 1.0847, 0.8942, 0.7205, 0.6031, 0.5231, 0.465, 0.421, 
0.3895, 0.3814, 0.3711, 0.3692, 0.3734, 0.3781, 0.3805, 0.3834, 
0.404, 0.4218, 0.3286, 0.3419, 0.3501, 0.3561, 0.3558, 0.3588, 
0.3652, 0.3694, 0.3716, 0.3731, 0.3698, 0.3575, 0.3416, 0.3129, 
0.2738, 0.2259, 0.1927, 0.1586, 0.1243, 0.1045, 0.0913, 0.0843, 
0.0813, 0.0844, 0.0879, 0.0905, 0.0929, 0.0946, 0.0947, 0.0931, 
0.0912, 0.045, 0.0493, 0.0556, 0.0618, 0.0699, 0.0797, 0.0905, 
0.1028, 0.1175, 0.1342, 0.1562, 0.1837, 0.2195, 0.2615, 0.3142, 
0.3705, 0.4169, 0.4557, 0.4927, 0.5289, 0.5647, 0.6016, 0.6313, 
0.663, 0.6813, 0.6988, 0.7338, 0.762, 0.7931, 0.8182, 0.8325, 
0.3546, 0.3558, 0.3642, 0.3728, 0.3708, 0.373, 0.3617, 0.3409, 
0.3146, 0.2955, 0.2765, 0.2705, 0.2696, 0.2707, 0.2667, 0.2695, 
0.2977, 0.3219, 0.3445, 0.366, 0.3838, 0.3962, 0.4006, 0.4019, 
0.3889, 0.3765, 0.3685, 0.3572, 0.3497, 0.3448, 0.336, 0.5913, 
0.6196, 0.6679, 0.6906, 0.6966, 0.6929, 0.6738, 0.6553, 0.6173, 
0.5868, 0.5531, 0.5175, 0.4779, 0.4365, 0.3909, 0.3385, 0.2914, 
0.2422, 0.1949, 0.1512, 0.1126, 0.096, 0.0886, 0.0818, 0.0722, 
0.0708, 0.0749, 0.0795, 0.084, 0.0884, 0.0916, 1.7225, 1.9116, 
2.0701, 2.2643, 2.3661, 2.4276, 2.4563, 2.4979, 2.5428, 2.5349, 
2.5297, 2.4619, 2.3602, 2.2084, 2.036, 1.8794, 1.6888, 1.4636, 
1.2234, 0.9425, 0.6853, 0.4694, 0.2897, 0.1764, 0.1071, 0.0755, 
0.059, 0.0482, 0.0426, 0.0388, 0.0361, 4.5689, 4.5308, 4.5132, 
4.5107, 4.5039, 4.4862, 4.5083, 4.5585, 4.5235, 4.3895, 4.2981, 
4.156, 3.9117, 3.7771, 3.671, 3.5786, 3.5541, 3.5463, 3.5859, 
3.556, 3.5479, 3.5365, 3.5967, 3.7016, 3.7099, 3.8148, 3.9268, 
4.0046, 4.0296, 3.9728, 3.9141, 7.0826, 7.1996, 7.3625, 7.529, 
7.6878, 7.9937, 8.1965, 8.6984, 9.3071, 9.9103, 10.936, 11.8715, 
12.9045, 13.5709, 14.6169, 15.4318, 16.0884, 16.6487, 16.9708, 
17.0343, 17.2035, 16.9599, 16.8804, 16.5998, 16.9403, 17.0379, 
16.551, 16.5844, 16.4058, 16.4294, 16.6504, 2.2918, 2.2735, 2.2641, 
2.275, 2.2696, 2.2673, 2.2362, 2.2028, 2.1566, 2.1272, 2.0136, 
1.9496, 1.8169, 1.7454, 1.5744, 1.3721, 1.1806, 1.0561, 0.9277, 
0.8247, 0.8209, 0.886, 0.9396, 0.9964, 1.0496, 1.0703, 1.1155, 
1.1545, 1.1761, 1.1896, 1.1758, 2.2673, 2.3979, 2.5272, 2.5888, 
2.6485, 2.5902, 2.5422, 2.4076, 2.1818, 1.9597, 1.68, 1.4059, 
1.1581, 0.8921, 0.6965, 0.5331, 0.3875, 0.2485, 0.1643, 0.1037, 
0.0613, 0.0316, 0.0166, 0.0085, 0.0054, 0.0031, 0.0015, 5e-04, 
2e-04, 1e-04, 0, 0.2281, 0.2319, 0.2431, 0.2573, 0.2708, 0.2835, 
0.2953, 0.3084, 0.3218, 0.3303, 0.3486, 0.3595, 0.3703, 0.3814, 
0.3905, 0.4093, 0.4247, 0.457, 0.5003, 0.5475, 0.6024, 0.6748, 
0.7713, 0.8899, 1.0086, 1.1211, 1.224, 1.3282, 1.4284, 1.5409, 
1.638, 0.053, 0.0587, 0.0682, 0.0823, 0.1014, 0.1373, 0.1856, 
0.2564, 0.3446, 0.4744, 0.6597, 0.9041, 1.2193, 1.6114, 2.0252, 
2.5264, 3.0744, 3.588, 4.1038, 4.5957, 5.0674, 5.5739, 6.0489, 
6.4466, 6.8976, 7.1861, 7.5265, 7.8668, 8.0832, 8.3965, 8.6394, 
0.4436, 0.4583, 0.478, 0.5078, 0.5288, 0.5403, 0.5301, 0.5092, 
0.4734, 0.4298, 0.3994, 0.3737, 0.3495, 0.3526, 0.4004, 0.477, 
0.5702, 0.6644, 0.7582, 0.8512, 0.9291, 1.0014, 1.0422, 1.0965, 
1.148, 1.1433, 1.157, 1.1468, 1.0928, 1.066, 1.0166, 0.7116, 
0.7522, 0.8112, 0.8562, 0.8681, 0.8774, 0.9048, 0.9367, 0.939, 
0.983, 0.9863, 0.9787, 0.966, 0.8786, 0.8127, 0.7215, 0.6064, 
0.4709, 0.3694, 0.2835, 0.2197, 0.1813, 0.1529, 0.1301, 0.1141, 
0.0956, 0.0818, 0.0735, 0.0608, 0.049, 0.0383)), .Names = c("Ecoregion", 
"Species", "TStep", "Spnum", "Scenario", "KgBiomass"), row.names = c(1L, 
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 
16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 
29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 
42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 
55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L, 
81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 90L, 91L, 92L, 93L, 
94L, 95L, 96L, 97L, 98L, 99L, 100L, 101L, 102L, 103L, 104L, 105L, 
106L, 107L, 108L, 109L, 110L, 111L, 112L, 113L, 114L, 115L, 116L, 
117L, 118L, 119L, 120L, 121L, 122L, 123L, 124L, 125L, 126L, 127L, 
128L, 129L, 130L, 131L, 132L, 133L, 134L, 135L, 136L, 137L, 138L, 
139L, 140L, 141L, 142L, 143L, 144L, 145L, 146L, 147L, 148L, 149L, 
150L, 151L, 152L, 153L, 154L, 155L, 156L, 157L, 158L, 159L, 160L, 
161L, 162L, 163L, 164L, 165L, 166L, 167L, 168L, 169L, 170L, 171L, 
172L, 173L, 174L, 175L, 176L, 177L, 178L, 179L, 180L, 181L, 182L, 
183L, 184L, 185L, 186L, 187L, 188L, 189L, 190L, 191L, 192L, 193L, 
194L, 195L, 196L, 197L, 198L, 199L, 200L, 201L, 202L, 203L, 204L, 
205L, 206L, 207L, 208L, 209L, 210L, 211L, 212L, 213L, 214L, 215L, 
216L, 217L, 218L, 219L, 220L, 221L, 222L, 223L, 224L, 225L, 226L, 
227L, 228L, 229L, 230L, 231L, 232L, 233L, 234L, 235L, 236L, 237L, 
238L, 239L, 240L, 241L, 242L, 243L, 244L, 245L, 246L, 247L, 248L, 
249L, 250L, 251L, 252L, 253L, 254L, 255L, 256L, 257L, 258L, 259L, 
260L, 261L, 262L, 263L, 264L, 265L, 266L, 267L, 268L, 269L, 270L, 
271L, 272L, 273L, 274L, 275L, 276L, 277L, 278L, 279L, 838L, 839L, 
840L, 841L, 842L, 843L, 844L, 845L, 846L, 847L, 848L, 849L, 850L, 
851L, 852L, 853L, 854L, 855L, 856L, 857L, 858L, 859L, 860L, 861L, 
862L, 863L, 864L, 865L, 866L, 867L, 868L, 869L, 870L, 871L, 872L, 
873L, 874L, 875L, 876L, 877L, 878L, 879L, 880L, 881L, 882L, 883L, 
884L, 885L, 886L, 887L, 888L, 889L, 890L, 891L, 892L, 893L, 894L, 
895L, 896L, 897L, 898L, 899L, 900L, 901L, 902L, 903L, 904L, 905L, 
906L, 907L, 908L, 909L, 910L, 911L, 912L, 913L, 914L, 915L, 916L, 
917L, 918L, 919L, 920L, 921L, 922L, 923L, 924L, 925L, 926L, 927L, 
928L, 929L, 930L, 931L, 932L, 933L, 934L, 935L, 936L, 937L, 938L, 
939L, 940L, 941L, 942L, 943L, 944L, 945L, 946L, 947L, 948L, 949L, 
950L, 951L, 952L, 953L, 954L, 955L, 956L, 957L, 958L, 959L, 960L, 
961L, 962L, 963L, 964L, 965L, 966L, 967L, 968L, 969L, 970L, 971L, 
972L, 973L, 974L, 975L, 976L, 977L, 978L, 979L, 980L, 981L, 982L, 
983L, 984L, 985L, 986L, 987L, 988L, 989L, 990L, 991L, 992L, 993L, 
994L, 995L, 996L, 997L, 998L, 999L, 1000L, 1001L, 1002L, 1003L, 
1004L, 1005L, 1006L, 1007L, 1008L, 1009L, 1010L, 1011L, 1012L, 
1013L, 1014L, 1015L, 1016L, 1017L, 1018L, 1019L, 1020L, 1021L, 
1022L, 1023L, 1024L, 1025L, 1026L, 1027L, 1028L, 1029L, 1030L, 
1031L, 1032L, 1033L, 1034L, 1035L, 1036L, 1037L, 1038L, 1039L, 
1040L, 1041L, 1042L, 1043L, 1044L, 1045L, 1046L, 1047L, 1048L, 
1049L, 1050L, 1051L, 1052L, 1053L, 1054L, 1055L, 1056L, 1057L, 
1058L, 1059L, 1060L, 1061L, 1062L, 1063L, 1064L, 1065L, 1066L, 
1067L, 1068L, 1069L, 1070L, 1071L, 1072L, 1073L, 1074L, 1075L, 
1076L, 1077L, 1078L, 1079L, 1080L, 1081L, 1082L, 1083L, 1084L, 
1085L, 1086L, 1087L, 1088L, 1089L, 1090L, 1091L, 1092L, 1093L, 
1094L, 1095L, 1096L, 1097L, 1098L, 1099L, 1100L, 1101L, 1102L, 
1103L, 1104L, 1105L, 1106L, 1107L, 1108L, 1109L, 1110L, 1111L, 
1112L, 1113L, 1114L, 1115L, 1116L), class = "data.frame")
4

1 回答 1

1

您似乎想要从一种离散颜色连续转换到另一种颜色geom_line(),但这不会在 ggplot2 中发生。您将不得不忍受颜色之间的空间,因为调色板是离散的,并且您只能使用离散的调色板在同一行上获得不同的颜色。我能想到的弥合颜色之间差距的唯一方法是增加 TStep 的数量。由于您在其中一个场景中使用了虚线型,我不太明白为什么您“需要”有平滑的线条。

为了增加可用于 Ecoregion 的颜色数量,我使用了rainbow()基本图形中的定性调色板,但您也可以使用colorspace包来定义调色板,其中有多种选择。

选定的调色板:

# Function taken from example(colorspace::rainbow_hcl)
wheel <- function(col, radius = 1, ...)
   pie(rep(1, length(col)), col = col, radius = radius, ...)
wheel(rainbow(13))

这是我根据您提供的数据(13 个独特的生态区)得出的图形代码:

ggplot(regime_shift_part1, 
       aes(x = TStep, y = KgBiomass, colour=factor(Ecoregion))) + 
  # geom_point(size=2.2) +
   theme_bw() +
   scale_x_discrete(name="Time Step", breaks=(0:2)*100 + 50, 
                    labels=seq(2050, 2250, by = 100))+
   labs(title="Maximum Biomass Producing Region",
        colour = "Ecoregion", linetype = "Scenario") + 
   theme(text = element_text(size=12), axis.text.x = element_text(vjust=1)) +
   scale_y_continuous(name=expression(paste("Maximum Biomass (Kg m"^"-2",")"))) +
   geom_line(aes(linetype = factor(Scenario)), size = 1.5)+
   facet_wrap(~ Species) +
   scale_colour_manual(breaks = levels(factor(regime_shift_part1$Ecoregion)),
                       values = rainbow(13))

如果您尝试为 Ecoregion 创建连续的颜色渐变,您会收到来自以下的错误消息geom_line()

Error: geom_path: If you are using dotted or dashed lines, colour, size and linetype must be constant over the line
于 2013-03-26T11:15:15.250 回答