对于合并线型和色标的绘图,我很难制作出组合图例来显示所有四个选项。我看过this answer,但是,正如您在运行绘图代码时会发现的那样,这似乎不起作用-我得到正确的分类,但是无法打印图例的所有四个元素。我在做什么错了?
谢谢!
<Grid Grid.Row="0" Grid.Column="0" DataContext="{StaticResource xmldata}">
<TreeView Name="entryTree" ItemsSource="{Binding}"/>
</Grid>
这是情节代码
structure(list(Ocean.Regions = c("South Pacific", "South Pacific",
"South Pacific", "South Pacific", "South Pacific", "South Pacific",
"South Pacific", "South Pacific", "South Pacific", "South Pacific",
"South Pacific", "South Pacific", "South Pacific", "South Pacific",
"South Pacific", "South Pacific", "South Pacific", "South Pacific",
"South Pacific", "South Pacific", "South Pacific", "South Pacific",
"South Pacific", "South Pacific", "South Pacific", "South Pacific",
"South Pacific", "South Pacific", "South Pacific", "South Pacific",
"South Pacific", "South Pacific", "South Pacific", "South Pacific",
"South Pacific", "South Pacific", "South Pacific", "South Pacific",
"South Pacific", "South Pacific", "South Pacific", "South Pacific",
"South Pacific", "South Pacific"), binned_alt = c(0, 0, 1000,
1000, 2000, 2000, 3000, 3000, 4000, 4000, 5000, 5000, 6000, 6000,
7000, 7000, 8000, 8000, 9000, 9000, 10000, 10000, 11000, 11000,
12000, 0, 0, 1000, 1000, 2000, 3000, 4000, 4000, 5000, 7000,
8000, 8000, 9000, 9000, 10000, 10000, 11000, 11000, 12000), Meteorological_Season_Factor = structure(c(1L,
3L, 1L, 3L, 1L, 3L, 1L, 3L, 1L, 3L, 3L, 1L, 3L, 1L, 3L, 1L, 3L,
1L, 3L, 1L, 3L, 1L, 1L, 3L, 3L, 1L, 3L, 3L, 1L, 3L, 1L, 3L, 1L,
1L, 1L, 1L, 3L, 3L, 1L, 3L, 1L, 1L, 3L, 3L), .Label = c("Winter",
"Fall", "Summer", "Spring"), class = "factor"), Species = c("MEK",
"MEK", "MEK", "MEK", "MEK", "MEK", "MEK", "MEK", "MEK", "MEK",
"MEK", "MEK", "MEK", "MEK", "MEK", "MEK", "MEK", "MEK", "MEK",
"MEK", "MEK", "MEK", "MEK", "MEK", "MEK", "MEK", "MEK", "MEK",
"MEK", "MEK", "MEK", "MEK", "MEK", "MEK", "MEK", "MEK", "MEK",
"MEK", "MEK", "MEK", "MEK", "MEK", "MEK", "MEK"), `25%` = c(10.25,
23.95, 6.775, 12.45, 4.65, 5.675, 3.3, 5.5, 4.5, 5.275, 4.6,
0.348456848923605, 4.35, 0.524861878453039, 3.475, 0.289655172413793,
0.376811594202899, 0.289655172413793, 0.688259109311741, 0.524861878453039,
4.15, 0.524861878453039, 0.524861878453039, 0.688259109311741,
0.688259109311741, 13.4, 22.7, 12.45, 5.92241379310345, 5.4,
1.84364640883978, 5.2, 2.61724137931034, 5.9, 0.289655172413793,
0.289655172413793, 0.376811594202899, 11.1, 0.524861878453039,
10.1, 0.524861878453039, 0.524861878453039, 0.688259109311741,
0.688259109311741), `50%` = c(13.4, 28.45, 10.7, 17, 8.4, 9.85,
5.9, 7.25, 5.9, 5.65, 7.15, 1.01243093922652, 6, 0.524861878453039,
4.75, 0.524861878453039, 2.8, 0.289655172413793, 3.5, 0.524861878453039,
7.5, 0.524861878453039, 0.524861878453039, 0.688259109311741,
0.688259109311741, 14.2, 28.4, 17, 10.75, 6.5, 3.16243093922652,
5.2, 4.9448275862069, 5.9, 0.289655172413793, 0.289655172413793,
0.376811594202899, 11.1, 0.524861878453039, 10.3, 0.524861878453039,
0.524861878453039, 0.688259109311741, 0.688259109311741), `75%` = c(16,
33.9, 17.85, 19.1, 10.15, 16.2, 12.325, 10.3, 9.05, 7.175, 7.425,
3.775, 7.6, 0.524861878453039, 5.875, 0.524861878453039, 5, 0.524861878453039,
9, 0.524861878453039, 9.675, 1.31864640883978, 0.524861878453039,
1.69412955465587, 0.688259109311741, 14.5, 34.2, 19.1, 16.15,
13.2, 4.48121546961326, 5.2, 7.27241379310345, 5.9, 0.289655172413793,
0.407258525433416, 0.376811594202899, 11.1, 0.524861878453039,
10.5, 2.11243093922652, 0.524861878453039, 0.688259109311741,
0.688259109311741), Treatment = 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, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Clean Marine", "All Data"
), class = "factor")), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -44L))
答案 0 :(得分:1)
尝试一下。对正在使用的两个字段(mutate(hybrid = paste(Meteorological_Season_Factor, Treatment))
进行散列,然后将其用于颜色和线型(aes(...col = hybrid, linetype = hybrid)
),然后对两个{{1 }}函数。
这是您要找的东西吗? (P.S.我相信我按您使用标签和值的顺序使用了它们……也许唯一的问题是您已经换了其中的一些!)
scale