Change and modify diagram

Good morning I have made this two diagrams out from different tables.

I would like to ask you how I can change the color of the column depending on the result and how I can remove all the values in the second diagram (-0.5,0,0.5, etc) and only put 1 and 0.

Thank you very much for your help.

#> Warning: package 'ggplot2' was built under R version 3.6.3
install.packages("reprex", dependencies = TRUE)
#> package 'reprex' successfully unpacked and MD5 sums checked
#> The downloaded binary packages are in
#>  C:\Users\juanp\AppData\Local\Temp\RtmpS4mHKa\downloaded_packages
#> Warning: package 'reprex' was built under R version 3.6.3
setwd("C:/Users/juanp/Desktop/New article/r help") 

neuro <- read_csv("C:/Users/juanp/Desktop/New article/r help/neuro.csv")
#> Parsed with column specification:
#> cols(
#>   `NEURO SIGN` = col_character()
#> )

neuro0 <- read_csv("C:/Users/juanp/Desktop/New article/r help/neuro0.csv")
#> Parsed with column specification:
#> cols(
#>   `NEURO SIGN` = col_double()
#> )

ggplot(neuro, aes(x=neuro$`NEURO SIGN`))+geom_bar()

ggplot(neuro0, aes(x=neuro0$`NEURO SIGN`))+geom_bar()

#> No input provided and clipboard is not available.
#> Rendering reprex...

Created on 2020-04-21 by the reprex package (v0.3.0)

Hello. In future, please post a reproducible example. We do not have access to the CSV files on your machine and thus cannot replicate the graphs you've posted.

I've created some dummy data to demonstrate possible solutions to your issues.

Bar colours can be changed by passing the fill aesthetic to geom_bar(). As for your second issue, I'm guessing you have 0/1 values in the column but it's been read in as a double by read_csv(). That can be fixed by casting it to a factor before plotting.



data <- tibble(col_chr = sample(c("YES", "NO"), size = 800, replace = TRUE))

ggplot(data, aes(x = col_chr)) +
  geom_bar(aes(fill = col_chr))

data2 <- tibble(col_num = sample(c(0, 1), size = 800, replace = TRUE))

data2 %>% 
  mutate(col_num = as_factor(col_num)) %>% 
  ggplot(aes(x = col_num)) +

Created on 2020-04-21 by the reprex package (v0.3.0)

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.