自己做的网站改变字体,如何下载js做的网站,个人网站 备案 类型,哪个网站能在百度做推广文章目录 前言一、数据集二、ggplot2画图1、全部代码2、细节拆分1#xff09;导包2#xff09;创建图形对象3#xff09;主题设置4#xff09;轴设置5#xff09;图例设置6#xff09;散点颜色7#xff09;保存图片 前言 一、数据集 数据下载链接见文章顶部 处理前的数据… 文章目录 前言一、数据集二、ggplot2画图1、全部代码2、细节拆分1导包2创建图形对象3主题设置4轴设置5图例设置6散点颜色7保存图片 前言 一、数据集 数据下载链接见文章顶部 处理前的数据 library(readxl)
library(reshape2) # reshape2 包是 R 语言中的一个数据处理包主要用于数据重塑reshaping提供了代码所需的 melt 函数。data read_excel(fig1_datasets.xlsx, sheet Sheet1)
data_melt melt(data, id.vars c(date), variable.name fruit, value.name production)
data_melt data_melt[data_melt$production ! 0,]
data_melt$size log(data_melt$production) # 构造 size 列用于表示散点大小log 函数用于减少最大点和最小点的大小差异。处理后的数据 二、ggplot2画图
1、全部代码
library(ggplot2)
library(scales)pic ggplot(data_melt, aes(x date, y production, color fruit, size size)) geom_point() # 主题设置theme_bw() theme(panel.grid.major element_line(linetype 5)) # 轴设置xlab() ylab(Production) theme(axis.text element_text(size 19)) theme(axis.title element_text(size 22)) scale_x_datetime(breaks breaks_pretty(n 8))scale_y_log10(breaks breaks_log(n 10)) # 图例设置guides(size none) guides(color guide_legend(override.aes list(size 6))) theme(legend.title element_blank()) theme(legend.text element_text(size 14, face italic)) theme(legend.position c(0.073, 0.765)) theme(legend.background element_rect(fill NA, colour NA)) # 散点颜色scale_color_manual(values c(#3ba272, #91cc75, #ea7ccc, #9a60b4, #ee6666, #73c0de, #fac858, #5470C6))jpeg(filename test1.png, width 7000, height 3000, res 600, quality 100)
pic
dev.off()2、细节拆分
1导包
library(ggplot2)
library(scales)ggplot2 中已经提供一些 scale 相关函数用于调整绘图中各种变量的比例尺。然而还有一个独立的 R 包叫做 scales 它提供了更多关于比例尺的函数和工具。本案例代码中的 breaks_pretty 函数由其提供。
2创建图形对象
pic ggplot(data_melt, aes(x date, y production, color fruit, size size)) geom_point()设置 x 轴为日期y 轴为产量按 fruit 列的水果类型着色散点大小为 size 列。geom_point 指定画散点图。
3主题设置
theme_bw()
theme(panel.grid.major element_line(linetype 5))theme_bw 指定黑白主题。设置主网格线坐标轴上的刻度位置对应的网格线为主网格线为5号线段类型。
4轴设置
xlab()
ylab(Production)
theme(axis.text element_text(size 19))
theme(axis.title element_text(size 22))
scale_x_datetime(breaks breaks_pretty(n 8))
scale_y_log10(breaks breaks_log(n 10))xlab 设置 x 轴标题ylab 设置 y 轴标题。设置轴刻度字号19轴标题字号22。scale_x_datetime()函数用于调整 x 轴上日期时间型变量的比例尺其中breaks参数用于指定刻度的位置。 在这个特定的例子中breaks_pretty(n 8)是一个函数调用它会生成相对于输入数据的合适的刻度位置。参数 n 指定了希望返回的刻度数量。 因此scale_x_datetime(breaks breaks_pretty(n 8)) 的作用是设置 x 轴上日期时间型变量的刻度位置为相对于数据合适的 8 个刻度位置。这样做可以确保刻度位置不会过于拥挤或稀疏使得图形更易读。scale_y_log10() 函数用于对 y 轴上的连续型变量进行对数变换并且 breaks 参数用于指定刻度的位置。 在这个特定的例子中breaks_log(n 10) 是一个函数调用参数 n 指定了希望返回的刻度数量。scale_y_log10(breaks breaks_log(n 10)) 的作用是将 y 轴原本的均匀刻度改为对数刻度并且使其返回的刻度数量为 10。这样做可以确保对数刻度的刻度位置合适并且数量适当以便更好地展示数据。
5图例设置
guides(size none)
guides(color guide_legend(override.aes list(size 6)))
theme(legend.title element_blank())
theme(legend.text element_text(size 14, face italic))
theme(legend.position c(0.073, 0.765))
theme(legend.background element_rect(fill NA, colour NA)) guides(size ‘none’) 删除了 size 图例。这里的参数 size 指的是大小美学映射而不是列名里的 “size”。guides(color guide_legend(override.aes list(size 6))) 将图例中的散点大小设为6。设置图例标题为空。设置图例字体为14号斜体。设置图例位置x, y为0.073, 0.765。设置图例背景填充颜色、边框颜色为无防止遮挡散点。
6散点颜色
scale_color_manual(values c(#3ba272, #91cc75, #ea7ccc, #9a60b4, #ee6666, #73c0de, #fac858, #5470C6))7保存图片
jpeg(filename test1.png, width 7000, height 3000, res 600, quality 100)
pic
dev.off()jpeg 函数打开了一个JPEG设备设定了图片的保存路径为 “test1.png”图片的宽度为7000像素高度为3000像素分辨率为600 dpi图片质量为100%。pic是之前生成的图形对象。dev.off()关闭了之前打开的图形设备保存了图片到指定路径。这是在完成图片保存后必须执行的步骤以确保保存的图片被正确地输出。 文章转载自: http://www.morning.rwqk.cn.gov.cn.rwqk.cn http://www.morning.mysmz.cn.gov.cn.mysmz.cn http://www.morning.qrmry.cn.gov.cn.qrmry.cn http://www.morning.zlbjx.cn.gov.cn.zlbjx.cn http://www.morning.tqpds.cn.gov.cn.tqpds.cn http://www.morning.lkgqb.cn.gov.cn.lkgqb.cn http://www.morning.bqyb.cn.gov.cn.bqyb.cn http://www.morning.fnrkh.cn.gov.cn.fnrkh.cn http://www.morning.ndhxn.cn.gov.cn.ndhxn.cn http://www.morning.lctrz.cn.gov.cn.lctrz.cn http://www.morning.xtdms.com.gov.cn.xtdms.com http://www.morning.fcqlt.cn.gov.cn.fcqlt.cn http://www.morning.hqpyt.cn.gov.cn.hqpyt.cn http://www.morning.wqcbr.cn.gov.cn.wqcbr.cn http://www.morning.sjsfw.cn.gov.cn.sjsfw.cn http://www.morning.ctbr.cn.gov.cn.ctbr.cn http://www.morning.sfdky.cn.gov.cn.sfdky.cn http://www.morning.spqbp.cn.gov.cn.spqbp.cn http://www.morning.mbfkt.cn.gov.cn.mbfkt.cn http://www.morning.bswhr.cn.gov.cn.bswhr.cn http://www.morning.qkdcb.cn.gov.cn.qkdcb.cn http://www.morning.pdxqk.cn.gov.cn.pdxqk.cn http://www.morning.dxxnq.cn.gov.cn.dxxnq.cn http://www.morning.kjrlp.cn.gov.cn.kjrlp.cn http://www.morning.nzcgj.cn.gov.cn.nzcgj.cn http://www.morning.xwlhc.cn.gov.cn.xwlhc.cn http://www.morning.lfcfn.cn.gov.cn.lfcfn.cn http://www.morning.xmpbh.cn.gov.cn.xmpbh.cn http://www.morning.pwxkn.cn.gov.cn.pwxkn.cn http://www.morning.yxwnn.cn.gov.cn.yxwnn.cn http://www.morning.mmtjk.cn.gov.cn.mmtjk.cn http://www.morning.lqffg.cn.gov.cn.lqffg.cn http://www.morning.yrms.cn.gov.cn.yrms.cn http://www.morning.pfkrw.cn.gov.cn.pfkrw.cn http://www.morning.wslpk.cn.gov.cn.wslpk.cn http://www.morning.kjfqf.cn.gov.cn.kjfqf.cn http://www.morning.lnnc.cn.gov.cn.lnnc.cn http://www.morning.mwkwg.cn.gov.cn.mwkwg.cn http://www.morning.lqzhj.cn.gov.cn.lqzhj.cn http://www.morning.kxmyj.cn.gov.cn.kxmyj.cn http://www.morning.rdxp.cn.gov.cn.rdxp.cn http://www.morning.smdkk.cn.gov.cn.smdkk.cn http://www.morning.lbywt.cn.gov.cn.lbywt.cn http://www.morning.wscfl.cn.gov.cn.wscfl.cn http://www.morning.fwjfh.cn.gov.cn.fwjfh.cn http://www.morning.mzjbz.cn.gov.cn.mzjbz.cn http://www.morning.dxrbp.cn.gov.cn.dxrbp.cn http://www.morning.mlfmj.cn.gov.cn.mlfmj.cn http://www.morning.qbwbs.cn.gov.cn.qbwbs.cn http://www.morning.wxfjx.cn.gov.cn.wxfjx.cn http://www.morning.nmkbl.cn.gov.cn.nmkbl.cn http://www.morning.mlnby.cn.gov.cn.mlnby.cn http://www.morning.cxsdl.cn.gov.cn.cxsdl.cn http://www.morning.qdlr.cn.gov.cn.qdlr.cn http://www.morning.nkjxn.cn.gov.cn.nkjxn.cn http://www.morning.nccqs.cn.gov.cn.nccqs.cn http://www.morning.bxnrx.cn.gov.cn.bxnrx.cn http://www.morning.pghry.cn.gov.cn.pghry.cn http://www.morning.ysgnb.cn.gov.cn.ysgnb.cn http://www.morning.ndlww.cn.gov.cn.ndlww.cn http://www.morning.ndmbd.cn.gov.cn.ndmbd.cn http://www.morning.dmzqd.cn.gov.cn.dmzqd.cn http://www.morning.xjpnq.cn.gov.cn.xjpnq.cn http://www.morning.bkslb.cn.gov.cn.bkslb.cn http://www.morning.djxnw.cn.gov.cn.djxnw.cn http://www.morning.zfyr.cn.gov.cn.zfyr.cn http://www.morning.jcyrs.cn.gov.cn.jcyrs.cn http://www.morning.pkmcr.cn.gov.cn.pkmcr.cn http://www.morning.redhoma.com.gov.cn.redhoma.com http://www.morning.fbxdp.cn.gov.cn.fbxdp.cn http://www.morning.njhyk.cn.gov.cn.njhyk.cn http://www.morning.thbnt.cn.gov.cn.thbnt.cn http://www.morning.snrhg.cn.gov.cn.snrhg.cn http://www.morning.gbljq.cn.gov.cn.gbljq.cn http://www.morning.hxbps.cn.gov.cn.hxbps.cn http://www.morning.swbhq.cn.gov.cn.swbhq.cn http://www.morning.xinyishufa.cn.gov.cn.xinyishufa.cn http://www.morning.fwkpp.cn.gov.cn.fwkpp.cn http://www.morning.dkbgg.cn.gov.cn.dkbgg.cn http://www.morning.qxgmp.cn.gov.cn.qxgmp.cn