Leaflet colours for polylines
<p>I would like to use a basic data.frame to get three polylines each of different colours</p>

<p>I am currently using the below code as an example.</p>

<pre><code>require(leaflet)
df &lt;- data.frame(lat=c(rnorm(20,50),rnorm(40,0),rnorm(40,-30)),
                 lon=rnorm(100),
                 group=rep(c("a","b","c"),times=c(20,40,40)),
                 col=rep(rainbow(3,alpha=NULL),times=c(20,40,40)))
leaflet(df) %&gt;% addTiles() %&gt;% addPolylines(lng=~lon,lat=~lat,color=~col)
</code></pre>

<p>But I get one continous line and and not the three separate lines for each group.</p>

<p>I can separate the lines but doing an very inelegant trick of:</p>

<pre><code>df_a &lt;- rbind(df[df$group=="a",],data.frame(lat=NA,lon=NA,group="a",col=NA))
df_b &lt;- rbind(df[df$group=="b",],data.frame(lat=NA,lon=NA,group="b",col=NA))
df_c &lt;- rbind(df[df$group=="c",],data.frame(lat=NA,lon=NA,group="c",col=NA))
df &lt;- rbind(df_a,df_b)
df &lt;- rbind(df,df_c) 
</code></pre>

<p>before the leaflet function, but it still does not solve the colour problem.</p>

<p>Any help to get the three polylines different colours would be much appreciated.</p>