Re: [R] Circular plot - polar plot code questions
Thanks yo Tim and Jim for useful suggestions re: my query on circular plots. Rethinking my goal, it appears Jim's suggestion of alternative linear plots make more sense and likley more intuitive for reader. Bruce __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Circular plot - polar plot code questions
Hi Bruce, Reading your message, I get the idea that you want a radial.plot with arcs to indicate "at least one bat is in this state'.This can be done with an addition to the rp.type= argument. If you already have what you want in this format, it may not be worth programming it. However, if you want "how many bats are in this state": m <- read.table( text="id T month P L 10100 20200 30300 41400 51510 61611 70711 80811 90901 1001000 1101100 1201200", header=TRUE) library(plotrix) png("batstate.png",width=600) kiteChart(t(m[,c("T","P","L")]), main="Bat state by month", xlab="Month",ylab="State", varlabels=c("Testiular enlargement","Pregnant","Lactatins"), timelabels=month.abb) dev.off() Jim On Mon, Apr 24, 2023 at 7:22 PM Bruce Miller wrote: > > Hi all... > I assume there are a host of GGplot2 users out there. > I have circular plot - polar plot code questions > I needed to create circular – polar plots of reproductive status for > bats. I found a great sample of how to do this here: > https://stackoverflow.com/questions/41081376/how-to-create-a-circular-plot-showing-monthly-presence-or-absence-using-radial-p > > I modified the sample code to meet the 3 data elements I am using the > "raw data" table below with T=testes enlarge, P= Pregnant and L= Lactating. > > library(data.table) > > > m <- fread("idTmonthPL > 10100 > 20200 > 30300 > 41400 > 51510 > 61611 > 70711 > 80811 > 90901 > 1001000 > 1101100 > 1201200") > # reshape from wide to long (as preferred by ggplot) > ml <- melt(m, measure.vars = c("T", "P", "L")) > > # create factors to ensure desired order > ml[, variable := factor(variable, levels = c("T", "P","L"))] > > ml[, fct_month := factor(month, levels = 1:12, labels = month.abb)] > library(ggplot2) > ggplot(ml[value != 0], aes(x = fct_month, y = variable, > group = variable, colour = variable)) + >geom_line(size = 3) + >scale_y_discrete(expand = c(0, 1), breaks = NULL) + >xlim(month.abb) + >coord_polar() + >theme_bw() + xlab(NULL) + ylab(NULL) > > This is creating a plot more or less as needed. 4 questions: > 1 Do I even need the ID field? Seems not useful. > 2 I assume the melt step can be avoided if my data is "Tidy" and long > format at the start, correct? > 3 How can I increase the weight of the month lines and labels > 4 Where can I add color choices for the 3 variables in the plot? Simply > adding an HTML color number to the “colour=variable” then plots the data > and labeling one value as that color. > > Tnx all. The list is always educational on a daily basis. > Cheers, > Bat Dude > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Circular plot - polar plot code questions
1) If you do not need it do not plot it. However, also consider how others will use your content. Might it be a trivial piece of information for you, but a critical piece of information for someone trying to use your content. A meta analysis, or just wanting to try to relate your outcomes to the results from their experiment. 2) There would be no need of melt() if the data is already in the proper format. The long format is not always the right format, though more often than not it is the right format (at least in my field of study). 3) google search something like "x-axis line weight ggplot" or something like that. There are excellent online resources to answer focused questions like that. 4) This might help: https://www.datanovia.com/en/blog/ggplot-colors-best-tricks-you-will-love/ Tim -Original Message- From: R-help On Behalf Of Bruce Miller Sent: Sunday, April 23, 2023 1:19 PM To: r-help@r-project.org Subject: [R] Circular plot - polar plot code questions [External Email] Hi all... I assume there are a host of GGplot2 users out there. I have circular plot - polar plot code questions I needed to create circular - polar plots of reproductive status for bats. I found a great sample of how to do this here: https://stackoverflow.com/questions/41081376/how-to-create-a-circular-plot-showing-monthly-presence-or-absence-using-radial-p I modified the sample code to meet the 3 data elements I am using the "raw data" table below with T=testes enlarge, P= Pregnant and L= Lactating. library(data.table) m <- fread("idTmonthPL 10100 20200 30300 41400 51510 61611 70711 80811 90901 1001000 1101100 1201200") # reshape from wide to long (as preferred by ggplot) ml <- melt(m, measure.vars = c("T", "P", "L")) # create factors to ensure desired order ml[, variable := factor(variable, levels = c("T", "P","L"))] ml[, fct_month := factor(month, levels = 1:12, labels = month.abb)] library(ggplot2) ggplot(ml[value != 0], aes(x = fct_month, y = variable, group = variable, colour = variable)) + geom_line(size = 3) + scale_y_discrete(expand = c(0, 1), breaks = NULL) + xlim(month.abb) + coord_polar() + theme_bw() + xlab(NULL) + ylab(NULL) This is creating a plot more or less as needed. 4 questions: 1 Do I even need the ID field? Seems not useful. 2 I assume the melt step can be avoided if my data is "Tidy" and long format at the start, correct? 3 How can I increase the weight of the month lines and labels 4 Where can I add color choices for the 3 variables in the plot? Simply adding an HTML color number to the "colour=variable" then plots the data and labeling one value as that color. Tnx all. The list is always educational on a daily basis. Cheers, Bat Dude [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Circular plot - polar plot code questions
Hi all... I assume there are a host of GGplot2 users out there. I have circular plot - polar plot code questions I needed to create circular – polar plots of reproductive status for bats. I found a great sample of how to do this here: https://stackoverflow.com/questions/41081376/how-to-create-a-circular-plot-showing-monthly-presence-or-absence-using-radial-p I modified the sample code to meet the 3 data elements I am using the "raw data" table below with T=testes enlarge, P= Pregnant and L= Lactating. library(data.table) m <- fread("id T month P L 1 0 1 0 0 2 0 2 0 0 3 0 3 0 0 4 1 4 0 0 5 1 5 1 0 6 1 6 1 1 7 0 7 1 1 8 0 8 1 1 9 0 9 0 1 10 0 10 0 0 11 0 11 0 0 12 0 12 0 0") # reshape from wide to long (as preferred by ggplot) ml <- melt(m, measure.vars = c("T", "P", "L")) # create factors to ensure desired order ml[, variable := factor(variable, levels = c("T", "P","L"))] ml[, fct_month := factor(month, levels = 1:12, labels = month.abb)] library(ggplot2) ggplot(ml[value != 0], aes(x = fct_month, y = variable, group = variable, colour = variable)) + geom_line(size = 3) + scale_y_discrete(expand = c(0, 1), breaks = NULL) + xlim(month.abb) + coord_polar() + theme_bw() + xlab(NULL) + ylab(NULL) This is creating a plot more or less as needed. 4 questions: 1 Do I even need the ID field? Seems not useful. 2 I assume the melt step can be avoided if my data is "Tidy" and long format at the start, correct? 3 How can I increase the weight of the month lines and labels 4 Where can I add color choices for the 3 variables in the plot? Simply adding an HTML color number to the “colour=variable” then plots the data and labeling one value as that color. Tnx all. The list is always educational on a daily basis. Cheers, Bat Dude [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.