如何更改两行之一的线型

时间:2019-03-30 01:18:43

标签: r ggplot2

我想更改绘图中两条线之一的线型,只将“ line1”变成虚线。

我的情节:

enter image description here

我的数据如下所示:

    Year Sex    value  Rate Group            
   <dbl> <chr>  <dbl> <dbl> <chr>            
 1  1912 Female    18 1.14  A 
 2  1912 Male      52 0.893 L     
 3  1913 Female    25 1.02  A 
 4  1913 Male      42 1.05  L      
 5  1914 Female    14 1.26  A 
 6  1914 Male      67 1.29  L      
 7  1915 Female    25 1.32  A 
 8  1915 Male      61 1.45  L     
 9  1916 Female    32 1.52  A 
10  1916 Male      71 1.64  L         
11  1917 Female    42 2.01  A 
12  1917 Male      92 1.87  L 

我的代码:

data %>% ggplot() + 
  geom_bar(aes(x = Year, y = value, fill= Sex), stat = "identity", 
           width=0.8,
           alpha=0.8) + 

  geom_line(aes(x = Year, y = Rate * 100, colour= Group),
            size = 1.0) + 

  scale_colour_manual(labels = c("line1","line2"), 
                      values = c("red","blue"))+ 

  scale_fill_manual(values = c("Female"="green","Male"="black"))+

  guides(fill=guide_legend(title = "Number"), 
         color=guide_legend(title= "Ratio"))

有人可以帮忙吗?我尝试了一段时间,但失败了。预先感谢。

1 个答案:

答案 0 :(得分:0)

如注释中所建议,并在每个scale _ * _ manual中使用“名称”一词来指定图例名称:

docker run --memory 4096m richardbronosky/node_build_box npm run install

enter image description here