Skip to content

coord_cartesian() cuts off axis labels #6378

Closed
@JWiley

Description

@JWiley

This plot works fine:

library(ggplot2)
testdat <- data.frame(
  Var = 1:4,
  Mean = c(1.5, 3, 2.2, 4.6),
  Low = c("Happy", "Peaceful", "Excited", "Content"),
  High = c("Sad", "Angry", "Hopeless", "Anxious"))

p <- ggplot(testdat, aes(x = Mean, y = Var)) +
      geom_point(shape = 18, size = 7, colour = "grey50") +
      scale_y_reverse("",
      breaks = seq_along(testdat$Low),
      labels = testdat$Low,
      sec.axis = dup_axis(
        breaks =  seq_along(testdat$Low),
        labels = testdat$High))
print(p)

Image

The y axes go from 1 to 4. If I want to specify limits on the x axis (the limits of possible response items on the affect adjectives) I try something like this:

p + coord_cartesian(
      xlim = c(1, 5),
      ylim = c(.5, 4.5),
      expand = FALSE)

Image

which results in that image. Actually the x and y limits look fine, but I can't understand why the labels on the left (Happy, etc) are all gone now. It did not use to do this, although I can't recall at what version it actually stopped / changed how it worked.
Whatever is expected, its hard for me to believe dropping one of my axis labels is the intended behaviour?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions