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

Circular density plot pick to 0 #6204

Closed
victorcat4 opened this issue Nov 26, 2024 · 3 comments
Closed

Circular density plot pick to 0 #6204

victorcat4 opened this issue Nov 26, 2024 · 3 comments

Comments

@victorcat4
Copy link

victorcat4 commented Nov 26, 2024

Hello,

In my dataset,

I have a observed bird and their direction, ranging from 0 to 360, which correspond to birds heading towards North.

To represent this, I want to make a circular density plot like so :

ggplot(echo %>% filter(!is.na(direction)), aes(x = direction)) +
geom_density(fill = "grey", adjust=0.5) +
coord_polar(theta = "x", start = 2*pi) + # Polar coordinates for circular plotting
labs(x = "", y = "Density", title = "Bird Direction") +
scale_x_continuous(
limits = c(0, 360), # Ensure the x-axis spans 0 to 360 degrees
breaks = c(0, 90, 180, 270), # Set the x-axis breaks at N, E, S, W
labels = c("N", "E", "S", "W") # Label breaks as compass directions
) +
theme(
axis.text.y = element_blank(), # Remove y-axis numbers
axis.ticks.y = element_blank() # Remove y-axis ticks
)

Image

The issue here is that their is a pick to 0 that does not represent the actual data.

Could someone help me out ?

Best regards

@teunbrand
Copy link
Collaborator

I'd recommend trying a KDE method that actually supports circular data and plotting the results. The geom_density() layer wraps stats::density(), which doesn't support circular data. I have no experience with it, but you could try out circular::density.circular() for your data.

@teunbrand teunbrand closed this as not planned Won't fix, can't repro, duplicate, stale Nov 26, 2024
@victorcat4
Copy link
Author

Any solution with ggplot ?

@teunbrand
Copy link
Collaborator

I don't know of any extensions implementing circular density, so unless you're interested in implenting such extension yourself, my advice is to just precalculate the density yourself and plot the results with ggplot2. If you need any help, I'd recommend trying the posit community or stack overflow. Implementing circular densities in ggplot2 itself is out of scope, per the same reasoning given in #5733.

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