Flower plot in R ?
2
6
Entering edit mode
6.7 years ago
dsarbashis ▴ 60

Can anyone suggest me how to generate the plot in B or C shown in the following paper in R. Thanks in advance

http://www.genomebiology.com/2013/14/2/R17/figure/F3?highres=y

R • 7.7k views
4
Entering edit mode

I don't know of a library that produces such plots.

That said, I don't find those plots very informative.  What does the plot add over a table?  What story is the plot meant to show?  Does the plot accurately portray the data?

3
Entering edit mode

It's likely that those were made in Adobe Illustrator or powerpoint. As Sean Davis said, those sorts of plots should be replaced with tables, which are easier to interpret.

1
Entering edit mode
0
Entering edit mode

Hi Sean,

Thank you for your response. Representing common and unique value between large number of data sets this is one of the good approach and better than a long table with numeric numbers.

4
Entering edit mode

I fully agree that a good plot is better than a table, but plots B and C are not good plots.  They are misleading and not quantitative.  To be more constructive, If there are overlaps between the groups, consider using a 2-d representation such as a heatmap with each cell representing the overlap between pairs of "petals".  If there are no overlaps, consider a bar plot of the "petals" or simply use a table.

0
Entering edit mode

I realize you asked for R, but if you can't find an R script, maybe you can use this:

http://matplotlib.org/examples/pylab_examples/ellipse_rotated.html

http://matplotlib.org/gallery.html

0
Entering edit mode

Thank you all for the helpful responses.

0
Entering edit mode

Isn't this just Venn diagram with many many entries? Just guessing.

0
Entering edit mode

It looks like one, but it isn't.

0
Entering edit mode

I didn't look too closely; just remembered seeing it at some point. :)

0
Entering edit mode

Dear dsarbashis, Did you find out how to plot these figures? I'm also trying to do it. Thanks!

0
Entering edit mode

Dear dsarbashis, Did you find out how to plot these figures? I'm also trying to build them but not able to find a proper library in R or Python. Thanks in advance

0
Entering edit mode

I would suggest to be careful with this kind of plot, which is prone to ambiguities and misinterpreation. See a paper on the closely-related petal plot for reference.

4
Entering edit mode
3.9 years ago
Zhilong Jia ★ 2.0k

The code is from http://www.cnblogs.com/xudongliang/p/7884667.html with a minor update. the R package plotrix is mainly used (ref this package to get parameter information).

flower_plot <- function(sample, value, start, a, b,
ellipse_col = rgb(135, 206, 235, 150, max = 255),
circle_col = rgb(0, 162, 214, max = 255),
circle_text_cex = 1, labels=labels) {
par( bty = "n", ann = F, xaxt = "n", yaxt = "n", mar = c(1,1,1,1))
plot(c(0,10),c(0,10),type="n")
n   <- length(sample)
deg <- 360 / n
res <- lapply(1:n, function(t){
plotrix::draw.ellipse(x = 5 + cos((start + deg * (t - 1)) * pi / 180),
y = 5 + sin((start + deg * (t - 1)) * pi / 180),
col = ellipse_col,
border = ellipse_col,
a = a, b = b, angle = deg * (t - 1))
text(x = 5 + 2.5 * cos((start + deg * (t - 1)) * pi / 180),
y = 5 + 2.5 * sin((start + deg * (t - 1)) * pi / 180),
value[t]
)

if (deg * (t - 1) < 180 && deg * (t - 1) > 0 ) {
text(x = 5 + 3.3 * cos((start + deg * (t - 1)) * pi / 180),
y = 5 + 3.3 * sin((start + deg * (t - 1)) * pi / 180),
sample[t],
srt = deg * (t - 1) - start,
cex = circle_text_cex
)

} else {
text(x = 5 + 3.3 * cos((start + deg * (t - 1)) * pi / 180),
y = 5 + 3.3 * sin((start + deg * (t - 1)) * pi / 180),
sample[t],
srt = deg * (t - 1) + start,
cex = circle_text_cex
)
}
})
plotrix::draw.circle(x = 5, y = 5, r = 1.5, col = circle_col, border = circle_col)
text(x = 4.7, y = 5, labels=labels)
}


Example like this:

flower_plot(c("WSM419", "A321", "M1", "M2", "M22", "M58",
"M102", "M161", "KH36b", "KH36c", "KH36d", "KH53a", "KH53b"),
c(519, 556, 83, 62, 415, 425, 357, 441, 22, 41, 33, 44, 43), 90, 0.5, 2, labels="core")


Results will be:

0
Entering edit mode

Thanks for your answer your function gives exact output. But if I wish to draw an another circle within the circle with same center (i.e. two circle with same center but different radius), what modifications we need to do? I tried draw.circle function with reduced radius but it was giving two different circles.

1
Entering edit mode

for example: add plotrix::draw.circle(x = 5, y = 5, r = 1, col = "red", border = circle_col) after the original plotrix::draw.circle line.

0
Entering edit mode

Hi Thank you for your jiffy reply. I too added the same but before the original plotrix::draw.circle line. So, I didn't get result but now we go it.

Thank you

0
Entering edit mode

Hi,

Sorry for not understanding much about codes. My questions are:

(1) The circle's label, whenever I plot the graph, seems to be a little bit to the left (not centralized), is there any way to fix that?

(2) How can I add a second line label just like the plot from the article (it is written S. medicae in the first line and 5036 in the second line)?

(3) Is there any way to change the colors and keep them transparent just like the figure from the article?

(4) Can I change the colors of each ellipse instead of making them all blue?

I am trying to make a flower plot similar to the one from figure 2 in this article: http://www.mdpi.com/1422-0067/17/8/1355/htm

Alec Watanabe

2
Entering edit mode
flower_plot2 <- function(sample, value, start, a, b,
ellipse_col = rgb(135, 206, 235, 150, max = 255),
circle_col = rgb(0, 162, 214, max = 255),
circle_text_cex = 1, labels=labels) {
par( bty = "n", ann = F, xaxt = "n", yaxt = "n", mar = c(1,1,1,1))
plot(c(0,10),c(0,10),type="n")
n   <- length(sample)
deg <- 360 / n
res <- lapply(1:n, function(t){
ellipse_col <- ellipse_col[t]
plotrix::draw.ellipse(x = 5 + cos((start + deg * (t - 1)) * pi / 180),
y = 5 + sin((start + deg * (t - 1)) * pi / 180),
col = ellipse_col,
border = ellipse_col,
a = a, b = b, angle = deg * (t - 1))
text(x = 5 + 2.5 * cos((start + deg * (t - 1)) * pi / 180),
y = 5 + 2.5 * sin((start + deg * (t - 1)) * pi / 180),
value[t]
)

if (deg * (t - 1) < 180 && deg * (t - 1) > 0 ) {
text(x = 5 + 3.3 * cos((start + deg * (t - 1)) * pi / 180),
y = 5 + 3.3 * sin((start + deg * (t - 1)) * pi / 180),
sample[t],
srt = deg * (t - 1) - start,
cex = circle_text_cex
)

} else {
text(x = 5 + 3.3 * cos((start + deg * (t - 1)) * pi / 180),
y = 5 + 3.3 * sin((start + deg * (t - 1)) * pi / 180),
sample[t],
srt = deg * (t - 1) + start,
cex = circle_text_cex
)
}
})
plotrix::draw.circle(x = 5, y = 5, r = 1.5, col = circle_col, border = circle_col )

# tune location by x and y.
text(x = 4.7, y = 5, labels=labels)
}

flower_plot2 (c("WSM419\nAAA", "A321", "M1", "M2", "M22", "M58",
"M102", "M161", "KH36b", "KH36c", "KH36d", "KH53a", "KH53b"),
c(519, 556, 83, 62, 415, 425, 357, 441, 22, 41, 33, 44, 43), 90, 0.5, 2, labels="core",
ellipse_col = topo.colors(13, alpha = 0.3),
circle_col = topo.colors(1, alpha = 0.7) )


1) tune x, y in the last line of the function flower_plot code as annotated. 2) I did not get your idea. maybe like "WSM419\nAAA". 3) input the transparented color will solve it. 4) parameter ellipse_col.

0
Entering edit mode

Hi,

Thank you! This worked really well. About the 2nd question, I was talking about the label in the circle (where it reads "core"). A minor change to the code you altered did the job. Thanks again.

Alec Watanabe

2
Entering edit mode
6 weeks ago
roder.thomas ▴ 20

I developed a small Python script to do this:

https://github.com/MrTomRod/flower-plot