File:Slope Field-modified.svg

From testwiki
Jump to navigation Jump to search
    Original file (SVG file, nominally 289 × 526 pixels, file size: 364 KB)

    This file is from Wikimedia Commons and may be used by other projects. The description on its file description page there is shown below.

    Summary

    Description
    English: Slope field of dy/dx = 2*x^2 − x − 2. Green lines indicate the slope.
    Date
    Source Own work
    Author Chen-Pan Liao

    R code

    library(ggplot2)
    
    f <- function(x, beta0) {
      (1 / 3) * x ^ 3 - (1 / 2) * x ^ 2 - 2 * x + beta0
    }
    
    d <-
      expand.grid(x = seq(-4, 4, 0.01), Intercept = c(-4, 0, 4))
    d$y <- with(d, f(x, Intercept))
    
    d.slope <-
      expand.grid(x = seq(-4, 4, 0.5),
                  y = seq(-10, 10, 0.5))
    d.slope$slope <- with(d.slope, x ^ 2 - x - 2)
    d.slope$angle <- with(d.slope, atan(slope) / pi * 180)
    
    ggplot(d, aes(x, y)) +
      geom_hline(yintercept = 0) +
      geom_vline(xintercept = 0) +
      geom_text(data = d.slope,
                aes(angle = angle, label = "—"),
                color = 3,
                size = 2.5) +
      geom_line(aes(color = as.factor(Intercept), group = as.factor(Intercept), size = as.factor(Intercept))) +
      scale_x_continuous("x", breaks = seq(-5, 5, 1)) +
      scale_y_continuous("y", breaks = seq(-50, 50, 1), limits = c(-8, 6)) +
      theme(panel.background = element_blank()) +
      theme(text = element_text(size = 12)) +
      theme(legend.position = "top") +
      scale_color_manual(values = c('green', 'red', 'blue')) +
      scale_size_manual(values = 1:3) +
      guides(size = guide_legend("Intercept"), color = guide_legend("Intercept")) +
      coord_fixed() +
      windows(5, 6)
    

    Licensing

    I, the copyright holder of this work, hereby publish it under the following license:
    Creative Commons CC-Zero This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication.
    The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.

    Captions

    Slope field of dy/dx = 2*x^2 − x − 2

    Items portrayed in this file

    depicts

    1 November 2021

    image/svg+xml

    373,195 byte

    1f766b872abd858145bae5a7ced3de1ea2614612

    File history

    Click on a date/time to view the file as it appeared at that time.

    Date/TimeThumbnailDimensionsUserComment
    current13:20, 1 November 2021Thumbnail for version as of 13:20, 1 November 2021289 × 526 (364 KB)wikimediacommons>Chen-Pan Liaofixes

    There are no pages that use this file.