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

coord_polar(): moving y axis to the right does not move the tickmarks and tick values #2005

Closed
ibiris opened this issue Jan 18, 2017 · 5 comments
Assignees

Comments

@ibiris
Copy link

@ibiris ibiris commented Jan 18, 2017

Using the scale_y_continuous(position="right") I expected that the y axis (label + tickmarks and values) will move to the right. While this works with "normal" charts it does not seem to do the right thing with coord_polar().

Some example code. Point D is where I experience this issue

library(dplyr)
library(ggplot2)
library(scales)
library(reshape2)
library(tibble)

df = mtcars %>%
 rownames_to_column( var = "car" ) %>% 
 mutate_each(funs(rescale), -car) %>% 
 melt(id.vars=c('car'), measure.vars=colnames(mtcars)) %>% 
 arrange(car)

line_plot = df %>%
 filter(variable=='mpg') %>%
 ggplot(aes(x=car, y=value, group=1)) + 
 geom_line(color = 'purple')

# A. Normal line plot - works OK
print(line_plot)

# B. Line plot with the y axis placed on the right - works OK
print(line_plot + ggplot2::scale_y_continuous(position="right") )

# C. Default coord_polar plot - works OK
print(line_plot + coord_polar())

# D. coord_polar() with the y axis placed on the right... Does not work 
#      Tickmarks for the y-axis appear on the left side even if the axis label is
#      placed on the right. The order of switching the position of the y-axis relative
#      to the coord_polar() invocation does not seem to matter
print(line_plot + coord_polar() + ggplot2::scale_y_continuous(position="right"))
print(line_plot + ggplot2::scale_y_continuous(position="right") + coord_polar())
@hadley
Copy link
Member

@hadley hadley commented Jan 25, 2017

Thanks for providing some code that illustrates the problem — it's a great start 😄 However, your code is currently a bit too complicated: there's quite a bit of extraneous stuff in there that doesn't seem directly related to the problem. Can you please try and simplify your example some more? The more minimal you can make the reprex, the faster I can identify the problem and fix it.

(Please don't include session info unless it's explicitly asked for, or you've used reprex::reprex(..., si = TRUE) to hide it away. I've deleted it from your issue to avoid cluttering up the discussion)

@hadley hadley added the reprex label Jan 25, 2017
@ibiris
Copy link
Author

@ibiris ibiris commented Jan 30, 2017

# Really simple dataset
heights <- c(100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 
  230, 240, 250)
weights <- c(50.1, 55.1, 60.1, 65.1, 70.1, 75.1, 80.1, 85.1, 90.1, 95.1, 100.1, 
  105.1, 110.1, 115.1, 120.1, 125.1)

# put it in a data frame
df <- data.frame(heights = heights, weights = weights)

# Prepare a basic line plot
line_plot <- ggplot2::ggplot(df, ggplot2::aes(x = heights, y = weights, group = 1)) + 
  ggplot2::geom_line(color = "purple")

# Problem: when plotting in polar coordinates positioning the y-axis label and tickmarks to the right only
# moves the label, not the tickmarks
print(line_plot + ggplot2::coord_polar() + ggplot2::scale_y_continuous(position = "right"))

@hadley
Copy link
Member

@hadley hadley commented Jan 30, 2017

Thanks! I've made it a bit simpler still:

library(ggplot2)

df <- data.frame(
  heights = c(100, 110, 120, 130, 140, 150), 
  weights = c(50.1, 55.1, 60.1, 65.1, 70.1, 75.1)
)

plot <- ggplot(df, ggplot2::aes(x = heights, y = weights, group = 1)) + 
  geom_line(color = "purple") + 
  coord_polar()

# OK
plot 

# NOT OK: Label moves, but ticks/labels don't
plot + scale_y_continuous(position = "right")

@hadley
Copy link
Member

@hadley hadley commented Feb 13, 2017

@thomasp85 can you take a quick look at this one please?

@thomasp85
Copy link
Member

@thomasp85 thomasp85 commented Feb 13, 2017

Yes

@thomasp85 thomasp85 self-assigned this Feb 27, 2017
@hadley hadley closed this in #2062 Mar 1, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants