Hi,
I have a data for which I have plotted a bar graph. But I want the y-axis to be shown as % from 0 to 100. How can I do this?
library(tidyverse)
#> Warning: package 'tibble' was built under R version 4.1.2
library(scales)
#>
#> Attaching package: 'scales'
#> The following object is masked from 'package:purrr':
#>
#> discard
#> The following object is masked from 'package:readr':
#>
#> col_factor
nit<-tibble::tribble(
~online_class,
"Yes",
"Yes",
"Yes",
"Yes",
"Yes",
"No",
"Yes",
"No",
"Yes",
"Yes",
"Yes",
"No"
)
ggplot(nit,aes(online_class))+
geom_bar(aes(fill=online_class))+
geom_text(stat = 'count',aes(label=percent(..count../nrow(nit))))
I will just modify the data here. These are not of character type, but numeric as given below.
Is there something I can do so that I get count of each score and the scales are also in accordance with that?
library(tidyverse)
library(janitor)
#>
#> Attaching package: 'janitor'
#> The following objects are masked from 'package:stats':
#>
#> chisq.test, fisher.test
library(scales)
#>
#> Attaching package: 'scales'
#> The following object is masked from 'package:purrr':
#>
#> discard
#> The following object is masked from 'package:readr':
#>
#> col_factor
data<-tibble::tribble(
~student, ~l1c1_total,
"S001", 1L,
"S002", 2L,
"S003", 2L,
"S004", 1L,
"S005", 0L,
"S006", 0L,
"S007", 5L
)
data %>%
ggplot(aes(l1c1_total))+
geom_bar(fill="orange",stat = "count",width = 0.5)+
labs(title = "Performance in Identification and Sorting of shapes",
x="Question score",
y="% of students")+
geom_text(stat='count',aes(label=percent(..count../nrow(data))),vjust=-0.5)+
theme_minimal()
Created on 2022-08-01 by the reprex package (v2.0.1)
Sorry, I do not understand what you want. Do you want the y axis to display the count or the percent of the total counts. In the code you posted, you display the count but label it as a percentage.
On the y-axis I want to display %. Basically, this is the score of a few students. There are students with scores 0,1,2, etc. In the graph I want to display the % of students who got those particular scores. I hope it is clear now.