Antonio Pano
Antonio Pano

Reputation: 21

How to make a bar plot with two single integer values?

Ideally with ggplot.

My values are: a = 226.1405 b = 340.9898

Upvotes: 1

Views: 563

Answers (1)

akrun
akrun

Reputation: 887048

We could convert to a data.frame or tibble and reshape to 'long' format with pivot_longer before plotting with ggplot

library(dplyr)
library(ggplot2)
library(tidyr)
tibble(a, b) %>% 
   pivot_longer(everything()) %>%
  ggplot(aes(x = name, y = value)) + 
      geom_col()

-output

enter image description here


Or using base R, just create a named vector and use barplot

barplot(c(a = a, b = b))

data

a <-  226.1405
b <- 340.9898

Upvotes: 1

Related Questions