Linetypes

11 views
Skip to first unread message

Osmo Salomaa

unread,
Aug 27, 2009, 8:35:13 AM8/27/09
to ggplot2
Is there a way to use other linetypes than the six built-in ones? Can
I (easily) implement my own linetypes? I would specifically be
interested in solid double lines (=====) and solid ladder-lines
(--|--|--|-- and ==|==|==|==). These would be used for plotting on a
map.

-- Osmo

baptiste auguie

unread,
Aug 27, 2009, 9:06:08 AM8/27/09
to Osmo Salomaa, ggplot2
Hi,

It's easy to use custom linetypes but only in terms of spacing
specification, I believe (as in the rest of R graphics). See this
example,


library(maps)
states = map_data("state")
statenames = unique(states$region)
states <- subset(states, region %in% statenames[sample(1:length(statenames),5)])

ltys = c("22", "44", "13", "1343", "73", "2262", "12223242", "F282",
"F4448444", "224282F2", "F1")


qplot(long, lat, data = states, group = group,
linetype = factor(region), geom="path") +
scale_linetype_manual(values = ltys[1:5])

Making double lines and ladder-lines as you call them should be doable
if you superpose different geoms on top of each other, but it's
probably hard to automate. Try this for instance,


qplot(long, lat, data = states, group = group, geom="path",
linetype=I("solid"), size=I(2)) +
geom_path(size=1, colour="grey95") # match the background colour

HTH,

baptiste
--
_____________________________

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

http://newton.ex.ac.uk/research/emag
______________________________

Osmo Salomaa

unread,
Aug 28, 2009, 6:32:30 AM8/28/09
to ggplot2
> Making double lines and ladder-lines as you call them should be doable
> if you superpose different geoms on top of each other, but it's
> probably hard to automate. Try this for instance,

Thanks. Superposing lines doesn't always give me proper transparency
(as in your example), but it works well enough for thin lines.

-- Osmo

Colin Gillespie

unread,
Sep 1, 2009, 10:43:21 AM9/1/09
to ggplot2

> library(maps)
> states = map_data("state")
> statenames = unique(states$region)
> states <- subset(states, region %in% statenames[sample(1:length(statenames),5)])
>
> ltys = c("22", "44", "13", "1343", "73", "2262", "12223242", "F282",
> "F4448444", "224282F2", "F1")
>
> qplot(long, lat, data = states, group = group,
>         linetype = factor(region), geom="path") +
>         scale_linetype_manual(values = ltys[1:5])
Daft question, but how would you convert line types into hex? Would
would be the value for a solid line?

Colin

baptiste auguie

unread,
Sep 1, 2009, 11:03:25 AM9/1/09
to Colin Gillespie, ggplot2
> Daft question, but how would you convert line types into hex? Would
> would be the value for a solid line?
>
> Colin

I don't think there is an hex value for a solid (or blank for that
matter) line, but you can use "solid"

ltys = c("solid", "dashed", "51","15","11","FFAA")
grid.segments(rep(0,6),seq(0.2,0.8,len=6),rep(1,6),seq(0.2,0.8,len=6),gp=gpar(lty=ltys))

for the hex specification, you need an odd number of digits, and 0
isn't allowed as a length.

HTH,

baptiste
Reply all
Reply to author
Forward
0 new messages