2

Here is my plot:

gr1 <- c(1, 5, 15, 20, 30, 40)
gr3 <- c(1, 5, 10, 25, 40, 60, 80)
gr2 <- c(1, 15, 25, 30, 40)

df2<- data.frame (pos = c(gr1, gr2, gr3), group = c(rep(1, length(gr1)),
 rep(2, length(gr2)), rep(3, length(gr3))))
df2$cpos <- cumsum (df2$pos)
df2$y <- rep(3, length (df2$cpos))
df2$y1 <- rep(0.35, length (df2$cpos))

df3 <- data.frame (cpos = rep(df2$cpos, 2), 
group = rep(df2$group,2), yd = c(df2$y, df2$y1),
x2 = c(rep(1, length (df2$y)),
rep(2, length (df2$y1))))

cx <- ggplot(df3, aes(y = yd, x = cpos, fill=factor(x2)))
cx1 <- cx + geom_area(aes(stat = "identity", position="fill" ))
cx1 +  geom_point(aes(color = factor(group)), pch = 19, size = 4) + 
scale_fill_manual(values=c("blue", "yellow", "green")) + coord_polar()

enter image description here

I could not get rid of some of issues

(1) I could not change color of the points, color change only applied to circles.

(2) the plot additional points plotted at the center circle, which I do not want to plot. (they are additional csum points)

declaration: this post is related with the previous post

Bonus accidental art

As am working hard to solve the issues, I do an sunflower plot.

df2<- data.frame (pos = c(gr1, gr2, gr3), group = c(rep(1, length(gr1)),
 rep(2, length(gr2)), rep(3, length(gr3))))
df2$cpos <- cumsum (df2$pos)
df2$y <- rep(3, length (df2$cpos))
df2$y1 <- rep(0.01, length (df2$cpos))
df2$y3 <- rep(2, length (df2$cpos))

df3 <- data.frame (cpos = rep(df2$cpos, 3), group = c(rep(1, length (df2$y)),
 rep(2, length (df2$y)), rep(3, length (df2$y))),
 yd = c(df2$y, df2$y1, df2$y3), x3 = c(rep(1, length (df2$y)), 
 rep(2, length (df2$y1)),rep(2, length (df2$y1)) ))

makes flower

cx <- ggplot(df3, aes(y = yd, x = cpos, fill=factor(x3)))
cx1 <- cx + geom_area(aes(stat = "identity", position="fill" ))
cx2 <- cx1 +  geom_point(aes(color = factor(group)), pch = 19, size = 4) + 
  scale_fill_manual(values=c("yellow", "pink")) + coord_polar()
cx2 + theme_bw()+ opts(axis.line=theme_blank(),axis.text.y=theme_blank(),
 axis.ticks = theme_blank(), axis.title.y=theme_blank(), 
 plot.background=theme_blank(), panel.border=theme_blank())

enter image description here

1
  • 1
    ggplot makes a distinction between color and fill. You specify a color in your geom aes(), but a fill in the scale. Use scale_color_manual to fix your first question. Commented May 6, 2012 at 19:51

1 Answer 1

1

For your second question, is this what you want? The inner circle of points correspond to yd = 0.35 or x2 = 2 in the df3 data frame. Therefore, in the geom_point call, drop those points from the df3 data frame. Here, I've use subset.

# Your data
gr1 <- c(1, 5, 15, 20, 30, 40)
gr3 <- c(1, 5, 10, 25, 40, 60, 80)
gr2 <- c(1, 15, 25, 30, 40)

df2<- data.frame (pos = c(gr1, gr2, gr3), group = c(rep(1, length(gr1)),
 rep(2, length(gr2)), rep(3, length(gr3))))
df2$cpos <- cumsum (df2$pos)
df2$y <- rep(3, length (df2$cpos))
df2$y1 <- rep(0.35, length (df2$cpos))

df3 <- data.frame (cpos = rep(df2$cpos, 2), 
  group = rep(df2$group,2), yd = c(df2$y, df2$y1),
  x2 = c(rep(1, length (df2$y)),
  rep(2, length (df2$y1))))

# The plot
library(ggplot2)
cx <- ggplot(df3, aes(y = yd, x = cpos, fill=factor(x2)))
cx1 <- cx + geom_area(aes(stat = "identity", position="fill" ))
cx1 +  geom_point(data = subset(df3, x2 == 1), aes(color = factor(group)), 
  pch = 19, size = 4) + 
  scale_color_manual(values=c("blue", "yellow", "green"))  + coord_polar()

The result is:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.