0

I have this dataset: structure(list(new = c("No: 0.91", "Yes: 0.89", "All: 0.84")), row.names = c(NA, -3L), class = c("tbl_df", "tbl", "data.frame")) And I would like to create a plot with only the text like: enter image description here

But the text to be one below the other. So you have any idea?

1
  • Have a look at geom_text(check_overlap = TRUE) Commented Feb 7, 2023 at 12:29

2 Answers 2

2

One option would be to use nudge_y to shift the labels:

library(ggplot2)

ggplot() +
  geom_text(aes(
    x = 1, y = 1,
    label = c("No: 0.91", "Yes: 0.89", "All: 0.84")
  ), nudge_y = .05 * c(1, 0, -1))

Sign up to request clarification or add additional context in comments.

Comments

1

An alternative is to specify the y axis positions manually within aes

ggplot(dataset, aes(0, -seq_along(new) + 2)) +
  geom_text(aes(label = new, color = new)) +
  ylim(c(-2, 2)) +
  scale_color_brewer(palette = 'Set1', guide = 'none')

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.