Last active
January 21, 2021 23:49
-
-
Save hakyim/e37e8aeca52d832069a81750b4ca7296 to your computer and use it in GitHub Desktop.
scatter plot + rug + fivenum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(ggplot2); require(grid) | |
my.scatter.rug = function(df,xname,yname,main='myplot',round.digits=2) | |
{ ## df is data frame, xname is name of the column to be ploted in x axis | |
## http://stackoverflow.com/questions/8545035/scatterplot-with-marginal-histograms-in-ggplot2 | |
xy = mutate_(df, "x"=xname, "y"=yname) | |
pp <- ggplot(xy, aes(x, y)) + | |
# set the locations of the x-axis labels as Tukey's five numbers | |
scale_x_continuous(limit=c(min(xy$x), max(xy$x)), | |
breaks=round(fivenum(xy$x),round.digits)) + | |
# ditto for y-axis labels | |
scale_y_continuous(limit=c(min(xy$y), max(xy$y)), | |
breaks=round(fivenum(xy$y),round.digits)) + | |
# specify points | |
geom_point() + | |
# specify that we want the rug plot | |
geom_rug(size=0.1) + | |
# improve the data/ink ratio | |
theme_set(theme_minimal(base_size = 18)) + labs(x=xname,y=yname, title = main) | |
pp | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment