() p6 <- ggplot(mpg, aes(manufacturer)) + geom_bar() p7 <- ggplot(economics, aes(date, unemploy/pop)) + geom_line()#时间序列图 p8 <- ggplot(economics, aes(unemploy/pop, uempmed)) + geom_path() + geom_point() grid.arrange(p1, p2, p3, p4, p5, p6, p7, p8, nrow = 4)...
brks <- economics_m$date # plot ggplot(economics_m, aes(x=date)) + geom_line(aes(y=returns_perc)) + labs(title="Monthly Time Series", subtitle="Returns Percentage from Economics Dataset", caption="Source: Economics", y="Returns %") + # title and caption scale_x_date(labels = lbls...
x_time(breaks = datebreaks, date_format("%Y-%m")) POSIXt对象 p + scalex_datetime(breaks = datebreaks,date_format()) theme(axistext.x = element_text(angle=90, hjust=1)) 1 交换X轴Y轴 使用coordflip()来翻转坐标轴。 ggplot(Plant, aes(x=group, y=weight)) + geom_boxplot()...
方法2:通过将id设置为date字段,使用reforme2::Melt融合数据帧。然后只需添加一条geom_线,并将颜色美学设置为variable(这是在融化过程中创建的)。 # Approach 2: library(reshape2) # 融合数据 df <- melt(economics[, c("date", "pce", "unemploy")], id="date") head(df) # 绘图 ggplot(df) + ...
ggplot(ss, aes(x=date, y=unemploy))+ geom_step() 两个变量:x离散,y连续 使用数据集ToothGrowth,其中的变量len(Tooth length)是连续变量,dose是离散变量。 ToothGrowth$dose <- as.factor(ToothGrowth$dose) head(ToothGrowth) ## len supp dose
Time series (line and points) # install.packages("ggplot2")library(ggplot2)# Datadf<-economics[economics$date>as.Date("2000-01-01"),]ggplot(df,aes(x=date,y=unemploy))+geom_line()+geom_point() The variable passed toxinsideaesmust be in a data format. Check the class of the variable...
自定义外观(Customizing the Look and Feel) 前50个ggplot2可视化效果(top 50 ggplot2 Visualizations) ggplot2简介涵盖了有关构建简单ggplot以及修改组件和外观的基本知识;自定义外观是关于图像的自定义,如使用多图,自定义布局操作图例、注释;前50个ggplot2可视化效果应用在第1部分和第2部分中学到的知识来构造其他类型...
ggplot(chic,aes(x=date,y=temp))+geom_point(shape=21,size=2,stroke=1,color="#3cc08f",fill="#c08f3c")+labs(x="Year",y="Temperature (°F)") 分类变量颜色 如果我们想要给映射的颜色进行自定义,可以使用函数scale_color_manual :
Error in as.Date.numeric(X) : ‘origin’ must be supplied Error in hist.default : ‘x’ must be numeric ggplot2 Error: stat_count() must not be used with a y aesthetic ggplot2 Error: Aesthetics must be either length 1 or the same as the data ...
...) 2.使用ggplot2绘制条形图 #变量值的频数表,使用BOD数据,时间为x值,demand为y值,使用geom_col()函数 ggplot(BOD,aes(x=BOD$Time,Y=BOD$demand...,aes(x=factor(cyl)))+geom_bar() *旧版ggplot2使用geom_bar(stat='identity')创建条形图 新版可使用geom_col()代替 2.4绘制直方图.....