ggplot2: How to display data points in a circular 360 degree bar chart with an angle of 0 degrees?


username

I got a circular 360 degree bar chart where the angle (numeric x-axis) of each bar needs to be specified manually. In general the plot works fine except for data points where the angles are 0 respectively. 360 degrees. This line is removed and not drawn, not even with a bar width of 1.

Why did you do this? How can I draw a bar with a center value of 0 and a bar width of 20 (from -10 to 350 degrees to 10 degrees)?

Thanks!

MWE:

library(tidyverse)

# dummy data
data <- data.frame(
  variable = c(0, 90, 180, 270), 
  value = c(50, 100, 150, 200))

# plot
ggplot(data, aes(x = variable, y = value, fill = factor(variable))) +
  geom_col(width = 20)  + # Even with a widh of 1 the first datapoint is removed from the plot.
  scale_x_continuous(breaks = seq(from=0, to=359, by=10),  limits=c(0, 360)) +
  coord_polar(start = 0)
Alan Cameron

I don't see a simple general solution for drawing a bar that spans the wrapping points in polar coordinates, but it's easy to move the bounds and starting point to get the desired effect:

ggplot(data, aes(x = variable, y = value, fill = factor(variable))) +
  geom_col(width = 20)  + 
  scale_x_continuous(breaks = seq(0, 359, by = 10), limits = c(-10, 350)) +
  coord_polar(start = -pi/18, clip = "off")

enter image description here

Obviously if you try to draw the bars between 350 and 359 degrees instead of 0 and 9 degrees this will cause problems now, but assuming you don't want any of the bars to overlap, I guess that's not a problem.

Related


ggplot2 stacked bar chart using rows as data points

wax I have a set of data to plot like this: Now, use LibreOffice Calc in Ubunutu to draw. I try to do this in R with the following code: ggplot(DATA, aes(x="Samples", y="Count", fill=factor(Sample1)))+geom_bar(stat="identity") This doesn't give me a stacked b

ggplot2 stacked bar chart using rows as data points

wax I have a set of data to plot like this: Now, use LibreOffice Calc in Ubunutu to draw. I try to do this in R with the following code: ggplot(DATA, aes(x="Samples", y="Count", fill=factor(Sample1)))+geom_bar(stat="identity") This doesn't give me a stacked b

ggplot2 stacked bar chart using rows as data points

wax I have a set of data to plot like this: Now, use LibreOffice Calc in Ubunutu to draw. I try to do this in R with the following code: ggplot(DATA, aes(x="Samples", y="Count", fill=factor(Sample1)))+geom_bar(stat="identity") This doesn't give me a stacked b

ggplot2 stacked bar chart using rows as data points

wax I have a set of data to plot like this: Now, use LibreOffice Calc in Ubunutu to draw. I try to do this in R with the following code: ggplot(DATA, aes(x="Samples", y="Count", fill=factor(Sample1)))+geom_bar(stat="identity") This doesn't give me a stacked b

Normalize the angle to a range of 0 to 360 degrees?

Significant We have data type Angle in SwiftUI . This can store values in degrees or radians from -infinity to +infinity. I want to convert the angle to a value between 0 and 360. For example, by using something like wrap around mod : func normalize(_ angle: A

Normalize the angle to a range of 0 to 360 degrees?

Significant We have data type Angle in SwiftUI . This can store values in degrees or radians from -infinity to +infinity. I want to convert the angle to a value between 0 and 360. For example, by using something like wrap around mod : func normalize(_ angle: A

Display data values in a stacked bar chart in ggplot2

MYaseen208 I want to display data values in a stacked bar chart in ggplot2. Here is the code I tried Year <- c(rep(c("2006-07", "2007-08", "2008-09", "2009-10"), each = 4)) Category <- c(rep(c("A", "B", "C", "D"), times = 4)) Frequency <- c(168, 259, 226

Display data values in a stacked bar chart in ggplot2

MYaseen208 I want to display data values in a stacked bar chart in ggplot2. Here is the code I tried Year <- c(rep(c("2006-07", "2007-08", "2008-09", "2009-10"), each = 4)) Category <- c(rep(c("A", "B", "C", "D"), times = 4)) Frequency <- c(168, 259, 226

Display data values in a stacked bar chart in ggplot2

MYaseen208 I want to display data values in a stacked bar chart in ggplot2. Here is the code I tried Year <- c(rep(c("2006-07", "2007-08", "2008-09", "2009-10"), each = 4)) Category <- c(rep(c("A", "B", "C", "D"), times = 4)) Frequency <- c(168, 259, 226

Get 360 degree angle

growler I want to get a 360 degree angle... For my game I need to know where the player is going... The code here gets the proper angles, but only in 90 degree increments: (i.e. when I click the upper left quadrant, I get an angle of 0 to 90 degrees... and the

Get 360 degree angle

growler I want to get a 360 degree angle... For my game I need to know where the player is going... The code here gets the proper angles, but only in 90 degree increments: (ie when I click on the upper left quadrant, I get an angle of 0 to 90 degrees... and th

360 degree angle

Swamp I coded this code here: double cosine = (v1.x*v2.x+v1.y*v2.y)/(150*150); double radian = Math.acos(cosine); double angle = Math.toDegrees(radian); V1 and V2 are two vectors which are simple Point(s)() for simplicity. Now I

SKSpriteNode gets the angle value from 0 to 360 degrees

sash I rotate SKSpriteNode. I need to get the angle value in degrees. I use SKNode zRotation: print((childNode(withName: "wheel")?.zRotation)! * 180 / CGFloat.pi) Documentation says: Positive values indicate counterclockwise rotation. But as the wheel rotates

Add circular reference line to polar bar chart in ggplot2

Jack Thompson I am trying to add a circle geom_polygon()for adding reference lines to a radial bar chart. (I know this is not the ideal way to present this data, but it's not entirely up to me). After this question , I can create a nice circle: library(tidyver