Open mattnuttall00 opened 5 years ago
@mattnuttall00 duuuuuuuuuude you need ggplot2 and facet_wrap or facet_grid
ggplot(data = dat_master, aes(tot_pop)) + geom_histogram() + facet_wrap(province ~ . )
Oh. my. days.
I did try facet_grid right at the start and that didn't do what I needed, but I did not try facet_wrap.
That worked perfectly, just a note though:
I got an error when I did facet_wrap(Province ~ .)
, but facet_wrap(~Province)
did exactly what I need.
Thank you Anna!
Now please excuse me while I go and repeatedly bang my head against a wall
boom!! facet_wrap the ass out of that dataset!
Not sure whether I should be closing this issue or not. I guess it's worth leaving coding questions open so that other people can easily search for and find them in the future?
Probably best to leave open, at least until the number of issues gets to be out of control.
Hi SCC team,
I have been trying to figure out how to write a function which will streamline the creation of multiple histograms. The idea of course being to save me time, but I can't quite figure out how to do it and therefore I am in fact wasting time going round in circles. SCC to the rescue! Hopefully this will be a useful post for other folk who would like to dapple in UDF's
I have a fairly large data set of socioeconomic variables from Cambodia. There are 42 variables and 1621 observations (each observation is the value for a given variable in each Commune, which is just an administrative area). There is also a variable called 'Province' which is a larger administrative area. The structure is below
I have only recently started working on this data set, and so am in the process of doing some data exploration. To do this, I am wanting to do a lot of plotting, for example histograms, to identify outliers, errors etc. What I wanted to do first was to plot histograms of each variable at the 'Province' level, as I would be able to spot any unusual records. Now I know I can do it this way:
But to do this for 42 variables seems silly. I am sure a function can be written, so that I could simply call
and histograms for that variable for each province would be printed.
I have tried a few ways, but I am not getting very far, and seeing as I've never attempted a UDF before I though maybe best get some guidance! Below are some of the ways I've tried:
and
and
The method above is using the new dataframes created when subsetting by Province. E.g. in
histplot1(x=battambang)
- battambang is a dataframe.Unfortunately none of those ways are working. Any ideas would be most appreciated!