r - How to draw a nice arrow in ggplot2 -
i creating ggplot
chart want have arrows between 2 points. main task done geom_line(arrow = arrow())
. however, want have "beautiful" thick arrows. resizing arrow via size=
doesn't since messes head of arrow completely. illustrate problems:
create sample data , plot:
name <- c("a", "a", "b", "b", "c", "c") year <- c(2016, 2011, 2016, 2011, 2016, 2011) year <- as.factor(year) value <- c(1, 4, 1, 5, 2, 8) data <- data.frame(name, year, value) ggplot(data, aes(x=value, y=name)) + geom_point(size=5, aes(colour=year)) + geom_line(arrow = arrow(length=unit(0.30,"cm"), ends="first", type = "closed"))
the resulting plot looks that:
now i've tried "thicken" arrows...
ggplot(data, aes(x=value, y=name)) + geom_point(size=5, aes(colour=year)) + geom_line(arrow = arrow(length=unit(0.30,"cm"), ends="first", type = "closed"), size = 3)
that's result shown here:
my question: there way plot "beautiful" thick arrows?
i use geom_segment
create arrow. need modify data "long" "wide" format (usually using dcast
reshape2
or data.table
package). time tried using base
's reshape
function.
ggplot(data, aes(x=value, y=name)) + geom_point(size=5, aes(colour=year)) + geom_segment(data = reshape(data, v.names="value", idvar = "name", timevar = "year", direction = "wide"), aes(x=value.2011, xend=value.2016, y=name, yend=name), size = 2, arrow = arrow(length = unit(0.5, "cm")))
edit: found same issue pertains "closed" type arrows. now, try save plot vector graph (pdf or svg, using ggsave
or export menu in plots tab). result not "messy".
Comments
Post a Comment