例子 # Inserting datavacc<-data.frame(catgry=rep(c("Covishield","Covaxin"),each=2),dose=rep(c("D1","D2"),2),slots=c(33,45,66,50))library(ggplot2)# Plotting basic lines with multiple groupsplt<-ggplot(data=vacc,aes(x=dose,y=slots,group=catgry))+geom_line()+geom_point(color...
Plot with multiple lines Well plot both ‘psavert’ and ‘uempmed’ on the same line chart. Solution 1: Make two calls togeom_line(): ggplot(economics, aes(x=date)) + geom_line(aes(y = psavert), color ="darkred") + geom_line(aes(y = uempmed), color="steelblue", linetype=...
How to move a ggplot2 legend with multiple rows to the bottom of a plot in R, The space above and below the legend using ggplot2, Plotnine doesn't add legend
编者按:数据可视化是解析、理解和展示数据不可缺少的一部分。炫或不炫看个人喜好和功底,能否达意是最基本的要求---最合适的图示和配色表达最直观的含义。长文多图预警,这是关于ggplot2使用的极详细教程(190+图),是入门和晋级参考的不二手册。 前面部分是关于qplot的使用,后面是ggplot2图层的使用。原文使用R自带数据...
The example code below creates a bar chart from Boston snowfall data, and it has several lines of customizations that I’d like to use again with other data. The first code block is the initial graph:library(ggplot2)library(scales)library(rio)snowfall2000s <- import(“https://gist.github...
Let’s assume that we want to create a ggplot2 barchart with a line on top, where the bars represent the sample column and the line represents the responses column. In order to use the functions of theggplot2 package, we also need to install and load ggplot2. ...
分面:在一个图形中绘制多个图(Faceting: Draw multiple plots within one figure) 修改图背景,长轴和短轴(Modifying Plot Background, Major and Minor Axis) 参考文档 http://r-statistics.co/Complete-Ggplot2-Tutorial-Part1-With-R-Code.html 让我们从midwest数据集中的人口相对于面积的散点图开始。点的颜色...
theme_classic : theme with axis lines and no grid lines p + theme_minimal() 1. p + theme_classic() 1. ggthemes提供的主题 p+ggthemes::theme_economist() 1. 坐标轴:最大最小值 p <- ggplot(cars, aes(x=speed, y=dist))+geom_point() 1. 修改坐标轴范围有以下几种方式:1、不删除数据...
p+theme_gray(base_size = 14) p+theme_bw() theme_linedraw : black lines around the plot theme_light : light gray lines and axis (more attention towards the data) p + theme_linedraw() p + theme_light() theme_minimal: no background annotations theme_classic : theme with axis lines a...
# Define data frame with hline dat_hlines <- data.frame(cond=c("control","treatment"), hline=c(9,12)) d # The bars are from dat, but the lines are from dat_hlines bp + geom_errorbar(data=dat_hlines, aes(y=NULL, ymax=hline, ymin=hline), colour="#AA0000") dat <- re...