exp / log scaled version of cut?
In plotting with ggplot the graphing function geom_histogram() can do this for you. https://www.tutorialgateway.org/r-ggplot2-histogram/#:~:text=The%20syntax%20to%20draw%20a%20ggplot%20Histogram%20in,%3D%20FALSE%2C%20show.legend%20%3D%20NA%2C%20inherit.aes%20%3D%20TRUE%29 Binning the raw data could be done using case_when() see https://www.rdocumentation.org/packages/dplyr/versions/0.7.8/topics/case_when With case_when() you could create a new variable so that you have the original data to refer back to. You might be able to overlay a plot of the axes in the raw data and the graph in binned data. I am not sure that would make much sense, and might be a way to trick readers into making bad conclusions: plotting binned data onto a continuous axis. Might work better to plot the binned data and then change labels using commands like xlab(), ylab(), theme(axis_title.x=element_blank()), axis_title.x=element_text(), labs(x="my x", y="my y") http://www.sthda.com/english/wiki/ggplot2-axis-ticks-a-guide-to-customize-tick-marks-and-labels https://www.datanovia.com/en/blog/ggplot-axis-labels/ Depending on exactly what you want to do here. Regards, Tim -----Original Message----- From: R-help <r-help-bounces at r-project.org> On Behalf Of Uwe Ligges Sent: Thursday, February 3, 2022 7:42 AM To: Fredrik Karlsson <dargosch at gmail.com>; R-help <r-help at r-project.org> Subject: Re: [R] exp / log scaled version of cut? [External Email]
On 03.02.2022 11:06, Fredrik Karlsson wrote:
Dear list, For tasks involving people its often good to work with ages in exp or log scale, since either not much or very much happens in the first 10 years of life, and much less (or much more) happens the following years. For tables with age range summary statistics, I sometimes would like to have a function that would for instance cut a range of values into breaks exp() scale equidistance bins, but with unconverted values in the labels. Similar to the way log / exp scaling of figure axis tick marks work, but with a factor returned. i have not been able to find such a function. Is there one? Thanks! Fredrik Karlsson
Yes, cut(): x <- runif(100, 0, 100) cut(x, c(0, 10, 100)) Best, Uwe Ligges ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dhelp&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsRzsn7AkP-g&m=E5bX46POI6aWCVW2Sn1gYLSC19ff-eoqeKiPmpipinQEE2CU38mPX2ReGsGWTfwG&s=MsUQlOyfUie2u5p7BJAJzW-BHNtXOlFZMiq-hPxTRVQ&e= PLEASE do read the posting guide https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posting-2Dguide.html&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsRzsn7AkP-g&m=E5bX46POI6aWCVW2Sn1gYLSC19ff-eoqeKiPmpipinQEE2CU38mPX2ReGsGWTfwG&s=q8534zhXd2FeFS4Z_Dth5YadYUs4P_9ZXjxdohleFB0&e= and provide commented, minimal, self-contained, reproducible code.