Discussion:
Error: Mapping should be created with `aes() or `aes_()`.
g***@gmail.com
2018-08-30 04:27:02 UTC
Permalink
Hi,

I'm having this error then i check i did use aes. Anyone hv anyidea about
this ? Thanks.
contributions <- analyze_contributions(contributions_fp =
"C:/Users/UMSBIOTECH/Desktop/Shared_Folder/CaseControl/Picrust/MetagenomecontriKEGG/Galaxy2-[Normalize_by_Copy_Number_on_data_1]_bt.txt",
+ contributions_id = "Sample",
+ mappingfile_fp =
"C:/Users/UMSBIOTECH/Desktop/Shared_Folder/CaseControl/Picrust/MetagenomecontriKEGG/Mapping_File_CASE_CONTROL_edit.txt",
+ mappingfile_id = "NAME")
Importing files...
Converting identifiers to names...
Adding names to table...
Adding metadata to table...
# Plot contributions
contributions %>%
+ group_by(Gene, SampleType) %>%
+ mutate(Contribution_perc = ContributionPercentOfAllSamples * 100) %>%
+ filter(Contribution_perc >= 0) %>%
+ select(Gene, family, Contribution_perc) %>%
+ mutate(Contribution = Contribution_perc/sum(Contribution_perc) * 100)
%>%
+ ggplot(arrange(contributions, family), aes(x = SampleType, y =
Contribution, fill = family)) +
+ geom_bar(stat = "identity") +
+ theme(axis.text.x = element_text(size = 6)) +
+ scale_y_continuous(expand = c(0, 0), limits = c(0, 100)) +
+ theme_light(base_size = 18) +
+ scale_fill_brewer(palette = "Set1")
Adding missing grouping variables: `SampleType`
Error: Mapping should be created with `aes() or `aes_()`.

Regards,
Goh
--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility

To post: email ***@googlegroups.com
To unsubscribe: email ggplot2+***@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Brandon Hurr
2018-08-30 13:15:19 UTC
Permalink
Your problem is here:
mutate(Contribution = Contribution_perc/sum(Contribution_perc) * 100) %>%
+ ggplot(arrange(contributions, family), aes(x = SampleType, y =
Contribution, fill = family)) +

when you pipe to ggplot it looks like this to ggplot:
ggplot(., arrange(contributions, family), aes(x...)) +

Your first argument should be your data argument and second is aes(), but
you've got something else there so it's confused.

If it were me, I would take the arrange out of the ggplot call completely.
Like so:

contributions %>%

group_by(., Gene, SampleType) %>%

mutate(., Contribution_perc = ContributionPercentOfAllSamples * 100) %>%

filter(., Contribution_perc >= 0) %>%

select(., Gene, family, Contribution_perc) %>%

mutate(., Contribution = Contribution_perc/sum(Contribution_perc) * 100)
%>%

arrange(., family) %>%

ggplot(., aes(x = SampleType, y = Contribution, fill = family)) +

geom_bar(stat = "identity") +

theme(axis.text.x = element_text(size = 6)) +

scale_y_continuous(expand = c(0, 0), limits = c(0, 100)) +

theme_light(base_size = 18) +

scale_fill_brewer(palette = "Set1")

I would also get into the habit of making your data argument more obvious.
Just add ".," to every line like I've done. Or just remember that you need
to make sure your data argument is first.

Alternatively, you could split your data munging from your plotting by
creating a new object and then plotting that. Like so.

Cont2 <-

contributions %>%

group_by(Gene, SampleType) %>%

mutate(Contribution_perc = ContributionPercentOfAllSamples * 100) %>%

filter(Contribution_perc >= 0) %>%

select(Gene, family, Contribution_perc) %>%

mutate(Contribution = Contribution_perc/sum(Contribution_perc) * 100) %>%

arrange(., family)

ggplot(Cont2, aes(x = SampleType, y = Contribution, fill = family)) +

geom_bar(stat = "identity") +

theme(axis.text.x = element_text(size = 6)) +

scale_y_continuous(expand = c(0, 0), limits = c(0, 100)) +

theme_light(base_size = 18) +

scale_fill_brewer(palette = "Set1")


HTH,
B
Post by g***@gmail.com
Hi,
I'm having this error then i check i did use aes. Anyone hv anyidea about
this ? Thanks.
contributions <- analyze_contributions(contributions_fp =
"C:/Users/UMSBIOTECH/Desktop/Shared_Folder/CaseControl/Picrust/MetagenomecontriKEGG/Galaxy2-[Normalize_by_Copy_Number_on_data_1]_bt.txt",
+ contributions_id = "Sample",
+ mappingfile_fp =
"C:/Users/UMSBIOTECH/Desktop/Shared_Folder/CaseControl/Picrust/MetagenomecontriKEGG/Mapping_File_CASE_CONTROL_edit.txt",
+ mappingfile_id = "NAME")
Importing files...
Converting identifiers to names...
Adding names to table...
Adding metadata to table...
# Plot contributions
contributions %>%
+ group_by(Gene, SampleType) %>%
+ mutate(Contribution_perc = ContributionPercentOfAllSamples * 100) %>%
+ filter(Contribution_perc >= 0) %>%
+ select(Gene, family, Contribution_perc) %>%
+ mutate(Contribution = Contribution_perc/sum(Contribution_perc) * 100)
%>%
+ ggplot(arrange(contributions, family), aes(x = SampleType, y =
Contribution, fill = family)) +
+ geom_bar(stat = "identity") +
+ theme(axis.text.x = element_text(size = 6)) +
+ scale_y_continuous(expand = c(0, 0), limits = c(0, 100)) +
+ theme_light(base_size = 18) +
+ scale_fill_brewer(palette = "Set1")
Adding missing grouping variables: `SampleType`
Error: Mapping should be created with `aes() or `aes_()`.
Regards,
Goh
--
--
You received this message because you are subscribed to the ggplot2 mailing list.
https://github.com/hadley/devtools/wiki/Reproducibility
More options: http://groups.google.com/group/ggplot2
---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility

To post: email ***@googlegroups.com
To unsubscribe: email ggplot2+***@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...