[R] Unable to make plots using ggplot2

pooja sinha pj@|nh@07 @end|ng |rom gm@||@com
Mon Feb 17 02:00:51 CET 2020


Thanks for your suggestion and code.


Puja

On Sun, Feb 16, 2020 at 5:23 PM Rui Barradas <ruipbarradas using sapo.pt> wrote:

> Hello,
>
> Your error is that you are not plotting the values in your file
> See what is in df, it's one column only with 3 character strings,
> c("Young_Control", "Young_Treated", "CHG_methylation"). Those *are not*
> the names of columns, they are just strings.
>
> The right way of doing it is to reshape your data from wide format to
> long format first. I will reformat with tidyr::pivot_longer and pipe the
> result directly to ggplot.
>
> Also, given the large difference in the values plotted, I suggest you
> comment out the code line with "log10", it will plot the y axis in the
> logarithmic scale.
>
>
> library(tidyverse)
> library(ggplot2)
>
> df1 %>%
>    pivot_longer(
>      cols = c("Young_Control", "Young_Treated"),
>      names_to = "Treatment",
>      values_to = "Value"
>    ) %>%
>    ggplot(aes(x = CHG_methylation, y = Value, fill = Treatment)) +
>    geom_col(position = position_dodge(0.9)) +
>    #scale_y_continuous(trans = "log10") +
>    theme(axis.text.x = element_text(angle = 60, vjust = 1))
>
>
> Hope this helps,
>
> Rui Barradas
>
>
> Às 22:01 de 16/02/20, pooja sinha escreveu:
> > Hi All,
> >
> > I have data in excel with the following details:
> > CHG_methylation Young_Control Young_Treated
> > 0-10% 95.23 94.53
> > 10-20% 3.71 4.16
> > 20-30% 0.68 0.8
> > 30-40% 0.18 0.22
> > 40-50% 0.07 0.09
> > 50-60% 0.04 0.06
> > 60-70% 0.02 0.04
> > 70-80% 0.02 0.03
> > 80-90% 0.02 0.03
> > 90-100% 0.04 0.05
> > I am trying to plot the graph using ggplot2 but not successful yet. My
> code
> > is below:
> >
> > library(readxl)
> > library(dplyr)
> > library(tidyverse)
> > data2 <- read_excel("CHG_meth_plot1.xlsx")
> > df <- data2
> > df <- data.frame(var=c("Young_Control", "Young_Treated",
> "CHG_methylation"))
> > df
> >
> > ggplot(data = df, aes(x = var, y = CHG_methylation)) +
> >    geom_bar(aes(fill = CHG_methylation))
> >
> > I am getting error as something is wrong with my df. Also I needed to
> > create breaks in y-axis as I do not know whether it is possible in R or
> > not.
> > Any kind of help is highly appreciated.
> >
> > Thanks,
> > Puja
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list