首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

绘制带有下标的图例,并在R中插入存储值

在R中,可以使用plot函数绘制带有下标的图例,并使用text函数插入存储值。下面是一个示例代码:

代码语言:R
复制
# 创建一个简单的散点图
x <- 1:5
y <- c(2, 4, 6, 8, 10)
plot(x, y, pch = 16, col = "blue", xlab = "X", ylab = "Y")

# 定义图例的标签和存储值
labels <- c("A", "B", "C", "D", "E")
values <- c(2, 4, 6, 8, 10)

# 在图例中插入标签和存储值
legend("topright", legend = labels, pch = 16, col = "blue", bty = "n")
text(x, y, labels = values, pos = 3)

在这个示例中,我们首先使用plot函数创建了一个简单的散点图,然后使用legend函数在图的右上角插入了图例,其中legend参数中的legend指定了图例的标签,pch和col指定了散点的形状和颜色,bty = "n"表示不绘制图例的边框。

接下来,我们使用text函数在散点图中插入了存储值,其中text参数中的x和y指定了插入位置的坐标,labels参数指定了要插入的存储值,pos = 3表示存储值位于散点的上方。

请注意,这只是一个示例代码,具体的图例和存储值的位置和样式可以根据实际需求进行调整。另外,腾讯云相关产品和产品介绍链接地址需要根据具体情况进行提供。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

  • Python 利用Python操作excel表格之openyxl介绍Part2

    ## 绘图 c = LineChart() # 设置图标类型:LineChart 连线图 AreaChart 面积图 c.title = 'CPU利用率' # 设置生成图的报告名称 c.style = 10 # 设置图例样式 c.y_axis.title = '百分比' # 设置 Y 轴名称 c.x_axis.title = '时间' # 设置 X 轴名称 c.y_axis.scaling.min = 0 # 设置y轴坐标最的小值 c.y_axis.majorUnit = 10 # 设置主y轴坐标,两个“坐标刻度”直接的间隔 c.y_axis.scaling.max = 100 # 设置主y轴坐标的最大值 # 设置 data引用数据源:第2列到第列(包括第2,10列),第1行到第30行,包括第1, 30行 data = Reference(sheet, min_col=2, max_col=10, min_row=1, max_row=30) c.add_data(data, titles_from_data=True) # 设置x轴 坐标值,即轴标签(Label)(从第3列,第2行(包括第2行)开始取数据直到第30行(包括30行)) x_labels = Reference(sheet, min_col=1, min_row=2, max_row=30) c.set_categories(x_labels) c.width = 18 # 设置图表的宽度 单位 cm c.height = 8 # 设置图表的高度 单位 cm # 设置插入图表位置 cell = "A10" sheet.add_chart(c, cell) # 绘制双y坐标轴图表 sheet = work_book['DEV'] c1 = AreaChart() # 面积图 c1.title = '磁盘活动统计报告' c1.style = 10 # 10 13 11 c1.y_axis.title = '平均时长(毫秒)' c1.x_axis.title = '时间' c1.y_axis.majorGridlines = None first_row = [] # 存储第一行记录 # 获取第一行记录 for row in sheet.rows: for cell in row: first_row.append(cell.value) break # 拼接系列的方式 target_columns = ['await', 'svctm'] for target_column in target_columns: index = first_row.index(target_column) ref_obj = Reference(sheet, min_col=index + 1, min_row=2, max_row=300) series_obj = Series(ref_obj, title=target_column) c1.append(series_obj) x_labels = Reference(sheet, min_col=1, min_row=2, max_row=300) c1.set_categories(x_labels) c1.width = 18 c1.height = 8 c2 = LineChart() c2.y_axis.title = '磁盘利用率' c2.y_axis.scaling.min = 0 # 设置y轴坐标最的小值 #c2.y_axis.majorUnit = 5 # 设置主y轴坐标的坐标单位 c2.y_axis.scaling.max = 100 # 设置主y轴坐标的最大值 ref_obj = Reference(sheet, min_col=8, min_row=2, max_row=300) series_obj = Series(ref_obj, title='%util') c2.append(series_obj) s = c2.series[0] # 获取添加第一个系列 # 设置线条填充颜色,也是图例的颜色 s.graphicalProperties.line.solidFill = "DEB887" # 设置线形 可选值如下: # ['solid', 'dot', 'dash', 'lgDash', 'dashDo

    02
    领券