Example Data costs <- data.frame( Season=c("Spring","Summer","Autumn","Winter"), Rent = c(1000,1000, 1050, 1100), Lodger_1 = rep("Smith",4), Lodger_2 = rep("Taylor",4), Lodger_3 = c("Mark","Mark","Twain","Finn"), Lodger_4 = c("Twain","Twain","Mark","Sawyer"), Heating_1 = c(60, 10, 90, 150), Heating_2 = c(50, 0, 70, 120), Heating_3 = c(50, 0, 75, 120), Heating_4 = c(55, 0, 70, 160), Elevator_2 = c(20, 20, 20, 22), Elevator_3 = c(25, 25, 25, 28), Elevator_4 = c(30, 30, 30, 33), stringsAsFactors = FALSE ) knitr::kable(costs) Season Rent Lodger_1 Lodger_2 Lodger_3 Lodger_4 Heating_1 Heating_2 Heating_3 Heating_4 Elevator_2 Elevator_3 Elevator_4 Spring 1000 Smith Taylor Mark Twain 60 50 50 55 20 25 30 Summer 1000 Smith Taylor Mark Twain 10 0 0 0 20 25 30 Autumn 1050 Smith Taylor Twain Mark 90 70 75 70 20 25 30 Winter 1100 Smith Taylor Finn Sawyer 150 120 120 160 22 28 33 Tidying the data step by step library(tidyverse) ## -- Attaching packages ----------------------------------------------------------------------- tidyverse 1.
How to plot a matrix with ggplot? As gglot requires data as dataframes in long format, we have to reshape the matrix. In the example below, we calculate the mandelbrot set as a two dimensional matrix, reshape it via the melt function from the reshape package and plot it with gglot.
Preparation - load packages library(parallel) library(ggplot2) library(reshape2) The mandelbrot set The mandelbrot set is created by applying a specific function \(z^2+z\) iteratively on each point \(z=x+yi\) of the complex plane and record the number of iterations until the value exceeds a limit.
Some Python x = [1,2,3,4,5,6] y = [i*i for i in x] And some R df <- data.frame(x=py$x, y=py$y) knitr::kable(df) x y 1 1 2 4 3 9 4 16 5 25 6 36 And Python again from matplotlib import pyplot as pl pl.plot(r.df.x, r.df.y) pl.show() Now some LaTeX An inline \(\int_a^bf(x)dx\) formula and a block formula