Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

error while plotting hist plot for a dataframe in R

I have a data that look like this:

cis_distance_freq4
# A tibble: 6 × 2
  distance  freq
     <dbl> <dbl>
1        0    NA
2     1000  4380
3    10000  4381
4    40000  4535
5    80000  4536
6  1000000  4558

hist(cis_distance$freq)

I want to plot in such a way that x axis is distance and y axis is freq.
Does anyone know how to plot this.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Here’s the ggplot() solution, using geom_bar() with stat="identity".

library(ggplot2)
cis_distance_freq4 <- tibble::tribble(
~distance,  ~freq,
      0,    NA,
   1000,  4380,
  10000,  4381,
  40000,  4535,
  80000,  4536,
1000000,  4558)


ggplot(cis_distance_freq4, aes(x=as.factor(distance), y=freq)) + 
  geom_bar(stat="identity", width=.99)
#> Warning: Removed 1 rows containing missing values (`position_stack()`).

Created on 2023-03-28 with reprex v2.0.2

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading