Search notes:

R data visualization: scatter plot

One of the most important R function to create a scatter plot is plot.
The following example is a simple demonstration on how to do that:
x11()

x <- seq(-6, 10, by=0.25) # c(-6:10)
y <- x*x*x/8 - 9*x -15

plot(x, y, 
    main="Scatter Plot"   , # Title
    sub ="plot 2 vectors" , # Sub title 
    xlab="x"              , # x label
    ylab="f(x)"           , # y label,
    xlim=c(-8,12)         , # range for x
    ylim=c(-45,15)        , # range for y
    col ="blue"           , # color
    pch = 19              , # 19=solid
    type="p"                # type (p = points, also possible: 
                            #       l = lines
                            #       b = both lines and points
                            #       c = b without p
                            #       o = overplotted
                            #       h = histogram
                            #       s = stair steps 
                            #       S = other steps,
                            #       n = not plotting
    )


z <- locator(1) # wait for mouse click or enter pressed
Github repository about-r, path: /graphics/data-visualization/scatter-plot/plot-2-vectors.R

type=p vs type=l

With type="p", plot produces points. This can be changed by using type="l", in which case plot will produce a line graph.

See also

Data visualization with R

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1742244870, '3.147.62.220', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/R/graphics/data-visualization/scatter-plot/index(75): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78