-
-
Save theironsamurai/6513a4c21030e8f90001 to your computer and use it in GitHub Desktop.
GGplot in Haskell
This file contains hidden or 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
demographicsAnalysis :: (MonadIO m, H.MonadR m) => Frame User -> m () | |
demographicsAnalysis fr = do | |
let demographics = fmap (rcast :: User -> Record '[HaskellExperience | |
,RecommendHaskell | |
,Occupation]) | |
(nubbed, counts) = view (runGetter ((,) <$> Getter (_1) <*> Getter _2)) | |
(unzip | |
(sortByLens (_1.recommendHaskell) | |
(sortByLens (_1.haskellExperience) | |
(countAll demographics)))) | |
exp = L.fold (foldList (haskellExperience)) nubbed | |
re = fmap fromIntegral $ L.fold (foldList (recommendHaskell)) nubbed :: [Int32] | |
occ = fmap fromIntegral $ L.fold (foldList (occupation)) nubbed :: [Int32] | |
liftIO $ do | |
print $ length counts | |
print $ length exp | |
print $ length re | |
[r| library (ggplot2) | |
png (filename= "expVsrec.png") | |
n <- length (exp_hs) | |
print (counts_hs) | |
print (length (counts_hs)) | |
print (n) | |
dat <- data.frame(xvar = exp_hs | |
,yvar = re_hs | |
) | |
print (dat) | |
print (ggplot (subset(dat, xvar>=-10) | |
, guide=FALSE | |
, aes (x=xvar, y=yvar)) + | |
geom_jitter (aes (size=counts_hs, fill=factor(occ_hs), shape=21, alpha=0.2)) + | |
scale_shape_identity () + | |
scale_fill_discrete (name = "Occupation" | |
,labels = c("Developer" | |
,"Manager" | |
,"Student" | |
,"Faculty" | |
,"Other")) + | |
# scale_size_area (max_size = 15) + | |
scale_x_continuous (name="Haskell Experience", limits=c(-2,6), breaks=seq(-1,6)) + | |
scale_y_continuous (name="Recommend Haskell", limits=c(-2,6), breaks=seq(-1,6)) + | |
scale_size_area (name = "Population size", max_size=15) | |
) | |
dev.off() |] | |
return () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment