Log scale in R help :) #1312
Replies: 2 comments
-
Have you tried to transform n in your figure, like this- y = log(n)
…On Fri, Oct 8, 2021 at 6:13 PM Delaney Lawson ***@***.***> wrote:
Hi all, I made this figure and table to represent metadata from the
nightingales datasheet. I want the y axis to be logarithmic so you can
actually see the values for each primary taxa. However, when i add the log
scale on the y axis, the data seems to be incorrect (shows P_generosa as
having more than O_lurida which is not correct). Anyone know how to solve
this? Or am I interpreting this incorrectly? Thanks :)
My code for the table is
data(nightingales)
nighttable <- (nightingales %>% group_by(Primary_taxa, Molecule) %>%
summarize(n = n(), .groups = "keep"))
options(knitr.kable.NA = '0')
nighttable %>% pivot_wider(names_from = Molecule, values_from = n) %>%
kbl(digits=2) %>% kable_classic(full_width = F, html_font = "Cambria")
My code for the first figure is
cols <- c("DNA" = "darkblue", "RNA" = "cornflowerblue", "Unknown" =
"darkgray")
ggplot(data = nighttable, aes(x = Primary_taxa, y = n, fill = Molecule)) +
geom_bar(position= "stack", stat="identity") +
scale_x_discrete(guide = guide_axis(angle = -90)) + theme_classic() +
scale_fill_manual(values = cols)
My code for the second figure is
cols <- c("DNA" = "darkblue", "RNA" = "cornflowerblue", "Unknown" =
"darkgray")
ggplot(data = nighttable, aes(x = Primary_taxa, y = n, fill = Molecule)) +
geom_bar(position= "stack", stat="identity") +
scale_x_discrete(guide = guide_axis(angle = -90)) + theme_classic() +
scale_fill_manual(values = cols) + scale_y_log10()
[image: Screen Shot 2021-10-08 at 4 05 20 PM]
<https://user-images.githubusercontent.com/73162507/136633193-e8c67d1c-e3e5-49f6-87cd-dfdf97872ce3.png>
[image: Screen Shot 2021-10-08 at 4 05 42 PM]
<https://user-images.githubusercontent.com/73162507/136633217-a4ba2bfb-aab7-45f1-90c0-59dc82fe9a60.png>
[image: Screen Shot 2021-10-08 at 4 05 53 PM]
<https://user-images.githubusercontent.com/73162507/136633227-1b872d2b-28aa-4b43-8033-47435c692b55.png>
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1312>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEDXA7JXVNJ25YCE26CUFMTUF53G5ANCNFSM5FUR3S7Q>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
sr320
-
Thanks for the suggestion Laura! I actually wanted to transform just the y axis instead of the data. I ended up needing to switch to using plotly instead of ggplot but I finally got it!! :) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi all, I made this figure and table to represent metadata from the nightingales datasheet. I want the y axis to be logarithmic so you can actually see the values for each primary taxa. However, when i add the log scale on the y axis, the data seems to be incorrect (shows P_generosa as having more than O_lurida which is not correct). Anyone know how to solve this? Or am I interpreting this incorrectly? Thanks :)
My code for the table is
My code for the first figure is
My code for the second figure is
Beta Was this translation helpful? Give feedback.
All reactions