Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ggpie changes the default order of label #203

Closed
WortJohn opened this issue Aug 15, 2019 · 5 comments
Closed

ggpie changes the default order of label #203

WortJohn opened this issue Aug 15, 2019 · 5 comments

Comments

@WortJohn
Copy link

Hello, @kassambara
When I use ggpie to plot a pie, I find the label is wrong. The following is my data:
data
And my code:

pielabels = paste(freq$GENE, paste(round(freq$FREQUENCY * 100, 2), "%", sep = ""), sep = "\n")
p = ggpie(freq, "FREQUENCY", label = pielabels, lab.pos = "out", lab.font = "white", fill = "GENE", color = "white", palette = "jco")
The following is the result and the order of label is wrong:
pie.pdf
Next, i check the data of plot. The order is changed.
da2
According to #116 , it is also not work.

@WortJohn
Copy link
Author

Sorry, according to #166 not 116, it is also not work.

@kassambara
Copy link
Owner

Thank you for pointing this issue. This is fixed by adding the pilabels into the data frame as follow:

freq <- data.frame(
  GENE = c("EGFR", "KRAS", "NTRK", "ALK", "RET", "BRAF", "ERBB2", "MET", "ROS1"),
  FREQUENCY = c(0.46, 0.26666667, 0.08, 0.04666667, 0.04666667, 0.0333333, 0.0333333, 0.0333333, 0.0133333)
)
freq$pielabels <- paste(freq$GENE, paste(round(freq$FREQUENCY * 100, 2), "%", sep = ""), sep = "\n")

ggpie(
  freq, "FREQUENCY", label = "pielabels", lab.pos = "out",
  lab.font = "white", fill = "GENE", color = "white", palette = "jco"
  )

Rplot

In the current version of ggpie(), the data is sorted internally. This sorting is not applied to labels when specified separately from the main input data. I'll update the function.

@kassambara
Copy link
Owner

Note also that, by default genes are ordered alphabetically in the plot. To keep the same order as in the table, modify the data as follow:

freq$GENE <- factor(freq$GENE, levels = freq$GENE)

You will end up with the plot below:

Rplot21

@kassambara
Copy link
Owner

fixed now, thanks!

You can install the latest dev version and try it: devtools::install_github("kassambara/ggpubr", dependencies = FALSE)

@WortJohn
Copy link
Author

Thanks for your solution very much. I get it and thank you again !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants