6

This is a simple example of what my barplot look like :

x <- data.frame(aa=c(0.2,0.6,0.1), dd = c(1,2,3))
x <- melt(x, "dd")
y <- data.frame(bb=c(0.4,0.5), dd = c(1,2))
y <- melt(y, "dd")
z <- data.frame(cc=c(0.5,0.25,0.1,0.05), dd = c(1,2,3,4))
z <- melt(z, "dd")

x=rbind(x,y,z)

col=c("white","grey","blue","white","red","white","green","blue","green")
ggplot(x, aes(x = variable, y = value)) + geom_bar(stat = "identity", fill = col)

I'm wondering if there is a way to have rounded ends for my bars, like with the lineend option for a line (http://sape.inf.usi.ch/quick-reference/ggplot2/lineend) ?

R_SOF
  • 268
  • 1
  • 7
  • I doubt that, would like to see if anyone knows solution to this problem. – pogibas Apr 24 '15 at 11:21
  • In barplot you need to compare the heights of different bars. so, the edge needs to be as straight as possible. Aesthetics is not the only thing to consider. purpose of plotting is different. – Koundy Apr 24 '15 at 11:24
  • Why would you need this? Are you trying to make them look like 3D pipes? – zx8754 Apr 24 '15 at 11:25
  • It's not really important. My bars are chromosomes, and usually chromosome's mosaics have rounded extremities ;) – R_SOF Apr 24 '15 at 11:53
  • 1
    Use [ggbio package](http://www.bioconductor.org/packages/release/bioc/html/ggbio.html), `Ideogram` function – zx8754 Apr 24 '15 at 11:58
  • 1
    Or here here is a starting point: `ggplot(x, aes(x=variable, y=value)) + geom_path(size=10, lineend="round",col=col)` – zx8754 Apr 24 '15 at 12:04
  • Thanks zx8754 ! It did the trick ! – R_SOF May 05 '15 at 06:06
  • 1
    @JustinB if you figured out how to use `geom_path()` to make the rounded corners, do you mind posting an answer? I'm curious to see how it came out. – LJW May 08 '15 at 04:32

1 Answers1

1

Here is an example where the bars have rounded ends, used with geom_line (geom_path), serving as a minimal example.

df1 <- data.frame( x=c(1,1,2,2,3,3),
                   y=c(1,7,1,4,1,5),
                   chr=c("one","one","two","two","three","three") )

ggplot( df1, aes(x,y, col=chr) ) + geom_line( lineend="round", lwd=10 )

ggplot_geom_line

Andre Wildberg
  • 12,344
  • 3
  • 12
  • 29