将轴刻度标签格式化为以百分比形式显示

编程入门 行业动态 更新时间:2024-10-11 07:30:18
本文介绍了将轴刻度标签格式化为以百分比形式显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在plotly中创建条形图,其中y轴表示0-1内的百分比或份额. y轴显示为0.05,而不是5.0%.

I am creating bar charts in plotly with y-axis representing percentages or shares within 0-1. The y-axis displays as 0.05 instead of 5.0%.

是否可以将y轴刻度标签显示为%##?

Is there a way to display y-axis tick labels as %##?

我尝试使用tickformat = "%",但这似乎不起作用.

I have tried using tickformat = "%" but that doesn't seem to be working.

推荐答案

您可以在plotly中使用layout进行此操作:

You can do this in plotly using layout:

p <- p %>% layout(yaxis = list(tickformat = "%"))

或者,如果您只想添加%并且不重新格式化数字,则:

Or if you want to only add % and do not reformat the numbers then:

p <- p %>% layout(yaxis = list(ticksuffix = "%"))

示例:

这是一个示例,显示了如何根据需要编辑y轴刻度. (例如乘以一个数字并加上后缀等)

Example:

This is an example that shows how to edit the y axis ticks as you wish. (like multiply by a number and add suffix, etc.)

我有以下代码和下图:

p <- plot_ly(z = eegmean$value, x = eegmean$xproj, y= eegmean$yproj, type = "contour") %>% layout(yaxis = list(range = c(0, 1)))

然后我进行如下修改,从而得到所需的输出:

Then I modify as below which gives me desired output:

g <- plot_ly(z = eegmean$value, x = eegmean$xproj, y= eegmean$yproj*100, type = "contour") %>% layout(yaxis = list(range = c(0, 100)))%>% layout(yaxis = list(ticksuffix = "%"))

eegmean <- structure(list(xproj = c(-4.36892281283989, 4.35956894475236, -3.66712823067503, 3.66912002532953, -6.74087785458615, 6.7287326256584, -3.06883681930631, 3.0727815538517, -3.05334720378955, 3.0570879596344, -3.79278629306119, 3.79086730312228, -7.07653326595358, 7.06235689946147, -7.90472265899708, 7.886291820964), yproj = c(0.0590663494057822, 0.0624572214558794, 4.86096691858553, 4.85057791325599, 5.19791938823655, 5.18984777332146, 9.40308855517187, 9.39510236056629, -9.35605694441838, -9.34632728162916, -4.81178659276704, -4.80386416586077, -5.3889955653921, -5.37981449730605, -0.00583969391994209, -0.00704057111565196 ), value = c(0.0606980290462218, 0.0608382874925463, 0.0517195368020531, 0.0531772440361526, 0.0204264049886253, 0.0177325467223879, 0.0392064861131087, 0.0425640060844722, 0.0788962178010734, 0.0740093285228833, 0.0749098131481143, 0.0759725415557911, 0.0688015959610801, 0.0762816652838652, 0.0548817124454006, 0.0646901969995537)), .Names = c("xproj", "yproj", "value"), row.names = c("C3", "C4", "F3", "F4", "F7", "F8", "FP1", "FP2", "O1", "O2", "P3", "P4", "P7", "P8", "T7", "T8"), class = "data.frame")

更多推荐

将轴刻度标签格式化为以百分比形式显示

本文发布于:2023-07-19 13:36:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1157040.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:刻度   百分比   形式   标签   格式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!