Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
3 added 1132 characters in body
source | link

large clusters: if overprinting is a problem, you could either use a lower alpha, so single points are dim, but overprining makes more intense colour. Or you switch to 2d histograms or density estimates.

require ("ggplot2")
  • ggplot (iris, aes (x = Sepal.Length, y = Sepal.Width, colour = Species)) + stat_density2d ()
    density
    You'd probably want to facet this...

  • ggplot (iris, aes (x = Sepal.Length, y = Sepal.Width, fill = Species)) + stat_binhex (bins=5, aes (alpha = ..count..)) + facet_grid (. ~ Species)
    hexbin
    While you can procude this plot also without facets, the prining order of the Species influnces the final picture.

  • You can avoid this if you're willing to get your hands a bit dirty (= link to explanation & code) and calculate mixed colours for the hexagons: enter image description here

  • Another useful thing is to use (hex)bins for high density areas, and plot single points for other parts:

    ggplot (df, aes (x = date, y = t5)) + 
      stat_binhex (data = df [df$t5 <= 0.5,], bins = nrow (df) / 250) +
          geom_point (data = df [df$t5 > 0.5,], aes (col = type), shape = 3) +
      scale_fill_gradient (low = "#AAAAFF", high = "#000080") +
      scale_colour_manual ("response type", 
        values = c (normal = "black", timeout = "red")) + 
      ylab ("t / s")
    

    enter image description here

 

For the sake of completeness of the plotting packages, let me also mention lattice:

require ("lattice")
  • xyplot(Sepal.Width ~ Sepal.Length | Species, iris, pch= 20)
    <code>xyplot(Sepal.Width ~ Sepal.Length | Species, iris, pch= 20)</code>

  • xyplot(Sepal.Width ~ Sepal.Length, iris, groups = iris$Species, pch= 20)
    <code>xyplot(Sepal.Width ~ Sepal.Length, iris, groups = iris$Species, pch= 20)</code>

  • xyplot(Sepal.Width ~ Sepal.Length | Species, iris, groups = iris$Species, pch= 20)
    <code>xyplot(Sepal.Width ~ Sepal.Length | Species, iris, groups = iris$Species, pch= 20)</code>

large clusters: if overprinting is a problem, you could either use a lower alpha, so single points are dim, but overprining makes more intense colour. Or you switch to 2d histograms or density estimates.

require ("ggplot2")
  • ggplot (iris, aes (x = Sepal.Length, y = Sepal.Width, colour = Species)) + stat_density2d ()
    density
    You'd probably want to facet this...

  • ggplot (iris, aes (x = Sepal.Length, y = Sepal.Width, fill = Species)) + stat_binhex (bins=5, aes (alpha = ..count..)) + facet_grid (. ~ Species)
    hexbin
    While you can procude this plot also without facets, the prining order of the Species influnces the final picture.

  • You can avoid this if you're willing to get your hands a bit dirty (= link to explanation & code) and calculate mixed colours for the hexagons: enter image description here

For the sake of completeness, let me also mention lattice:

require ("lattice")
  • xyplot(Sepal.Width ~ Sepal.Length | Species, iris, pch= 20)
    <code>xyplot(Sepal.Width ~ Sepal.Length | Species, iris, pch= 20)</code>

  • xyplot(Sepal.Width ~ Sepal.Length, iris, groups = iris$Species, pch= 20)
    <code>xyplot(Sepal.Width ~ Sepal.Length, iris, groups = iris$Species, pch= 20)</code>

  • xyplot(Sepal.Width ~ Sepal.Length | Species, iris, groups = iris$Species, pch= 20)
    <code>xyplot(Sepal.Width ~ Sepal.Length | Species, iris, groups = iris$Species, pch= 20)</code>

large clusters: if overprinting is a problem, you could either use a lower alpha, so single points are dim, but overprining makes more intense colour. Or you switch to 2d histograms or density estimates.

require ("ggplot2")
  • ggplot (iris, aes (x = Sepal.Length, y = Sepal.Width, colour = Species)) + stat_density2d ()
    density
    You'd probably want to facet this...

  • ggplot (iris, aes (x = Sepal.Length, y = Sepal.Width, fill = Species)) + stat_binhex (bins=5, aes (alpha = ..count..)) + facet_grid (. ~ Species)
    hexbin
    While you can procude this plot also without facets, the prining order of the Species influnces the final picture.

  • You can avoid this if you're willing to get your hands a bit dirty (= link to explanation & code) and calculate mixed colours for the hexagons: enter image description here

  • Another useful thing is to use (hex)bins for high density areas, and plot single points for other parts:

    ggplot (df, aes (x = date, y = t5)) + 
      stat_binhex (data = df [df$t5 <= 0.5,], bins = nrow (df) / 250) +
          geom_point (data = df [df$t5 > 0.5,], aes (col = type), shape = 3) +
      scale_fill_gradient (low = "#AAAAFF", high = "#000080") +
      scale_colour_manual ("response type", 
        values = c (normal = "black", timeout = "red")) + 
      ylab ("t / s")
    

    enter image description here

 

For the sake of completeness of the plotting packages, let me also mention lattice:

require ("lattice")
  • xyplot(Sepal.Width ~ Sepal.Length | Species, iris, pch= 20)
    <code>xyplot(Sepal.Width ~ Sepal.Length | Species, iris, pch= 20)</code>

  • xyplot(Sepal.Width ~ Sepal.Length, iris, groups = iris$Species, pch= 20)
    <code>xyplot(Sepal.Width ~ Sepal.Length, iris, groups = iris$Species, pch= 20)</code>

  • xyplot(Sepal.Width ~ Sepal.Length | Species, iris, groups = iris$Species, pch= 20)
    <code>xyplot(Sepal.Width ~ Sepal.Length | Species, iris, groups = iris$Species, pch= 20)</code>

2 added 1132 characters in body
source | link

large clusters: if overprinting is a problem, you could either use a lower alpha, so single points are dim, but overprining makes more intense colour. Or you switch to 2d histograms or density estimates.

require ("ggplot2")
  • ggplot (iris, aes (x = Sepal.Length, y = Sepal.Width, colour = Species)) + stat_density2d ()
    density
    You'd probably want to facet this...

  • ggplot (iris, aes (x = Sepal.Length, y = Sepal.Width, fill = Species)) + stat_binhex (bins=5, aes (alpha = ..count..)) + facet_grid (. ~ Species)
    hexbin
    While you can procude this plot also without facets, the prining order of the Species influnces the final picture.

  • You can avoid this if you're willing to get your hands a bit dirty (= link to explanation & code) and calculate mixed colours for the hexagons: enter image description here

For the sake of completeness, let me add the lattice versionalso mention lattice: 

require ("lattice")
  • xyplot(Sepal.Width ~ Sepal.Length | Species, iris, pch= 20)
    <code>xyplot(Sepal.Width ~ Sepal.Length | Species, iris, pch= 20)</code>

  • xyplot(Sepal.Width ~ Sepal.Length, iris, groups = iris$Species, pch= 20)
    <code>xyplot(Sepal.Width ~ Sepal.Length, iris, groups = iris$Species, pch= 20)</code>

  • xyplot(Sepal.Width ~ Sepal.Length | Species, iris, groups = iris$Species, pch= 20)
    <code>xyplot(Sepal.Width ~ Sepal.Length | Species, iris, groups = iris$Species, pch= 20)</code>

For the sake of completeness, let me add the lattice version:

  • xyplot(Sepal.Width ~ Sepal.Length | Species, iris, pch= 20)
    <code>xyplot(Sepal.Width ~ Sepal.Length | Species, iris, pch= 20)</code>

  • xyplot(Sepal.Width ~ Sepal.Length, iris, groups = iris$Species, pch= 20)
    <code>xyplot(Sepal.Width ~ Sepal.Length, iris, groups = iris$Species, pch= 20)</code>

  • xyplot(Sepal.Width ~ Sepal.Length | Species, iris, groups = iris$Species, pch= 20)
    <code>xyplot(Sepal.Width ~ Sepal.Length | Species, iris, groups = iris$Species, pch= 20)</code>

large clusters: if overprinting is a problem, you could either use a lower alpha, so single points are dim, but overprining makes more intense colour. Or you switch to 2d histograms or density estimates.

require ("ggplot2")
  • ggplot (iris, aes (x = Sepal.Length, y = Sepal.Width, colour = Species)) + stat_density2d ()
    density
    You'd probably want to facet this...

  • ggplot (iris, aes (x = Sepal.Length, y = Sepal.Width, fill = Species)) + stat_binhex (bins=5, aes (alpha = ..count..)) + facet_grid (. ~ Species)
    hexbin
    While you can procude this plot also without facets, the prining order of the Species influnces the final picture.

  • You can avoid this if you're willing to get your hands a bit dirty (= link to explanation & code) and calculate mixed colours for the hexagons: enter image description here

For the sake of completeness, let me also mention lattice: 

require ("lattice")
  • xyplot(Sepal.Width ~ Sepal.Length | Species, iris, pch= 20)
    <code>xyplot(Sepal.Width ~ Sepal.Length | Species, iris, pch= 20)</code>

  • xyplot(Sepal.Width ~ Sepal.Length, iris, groups = iris$Species, pch= 20)
    <code>xyplot(Sepal.Width ~ Sepal.Length, iris, groups = iris$Species, pch= 20)</code>

  • xyplot(Sepal.Width ~ Sepal.Length | Species, iris, groups = iris$Species, pch= 20)
    <code>xyplot(Sepal.Width ~ Sepal.Length | Species, iris, groups = iris$Species, pch= 20)</code>

1
source | link

For the sake of completeness, let me add the lattice version:

  • xyplot(Sepal.Width ~ Sepal.Length | Species, iris, pch= 20)
    <code>xyplot(Sepal.Width ~ Sepal.Length | Species, iris, pch= 20)</code>

  • xyplot(Sepal.Width ~ Sepal.Length, iris, groups = iris$Species, pch= 20)
    <code>xyplot(Sepal.Width ~ Sepal.Length, iris, groups = iris$Species, pch= 20)</code>

  • xyplot(Sepal.Width ~ Sepal.Length | Species, iris, groups = iris$Species, pch= 20)
    <code>xyplot(Sepal.Width ~ Sepal.Length | Species, iris, groups = iris$Species, pch= 20)</code>