- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这个数据:
structure(list(ID = structure(c(3L, 4L, 4L, 4L, 4L, 4L, 1L, 5L,
2L, 2L), .Label = c("015753e0-8574-4b13-88d7-627292d52272", "2721a25c-cc0e-43d3-abd2-b29a0da8b9d0",
"60a7614a-63bb-4bb9-91ac-520549853c19", "86735a77-b822-4320-b16e-1ff2b5535f5d",
"8ff4d254-291b-47d4-970a-82f29f8a51fb"), class = "factor"), Impact = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 3L, 2L, 3L, 3L), .Label = c("Extreme impact",
"Moderate impact", "Strong impact"), class = "factor"), Size_bribe = structure(c(1L,
3L, 3L, 3L, 3L, 3L, 2L, 4L, 1L, 1L), .Label = c("10,000 Afs",
"100 Afs", "100,000 Afs", "No payment made"), class = "factor"),
Abuse_type = structure(c(2L, 3L, 3L, 3L, 3L, 3L, 2L, 1L,
2L, 2L), .Label = c("Delay of service", "Payment of money",
"Threat of incarceration"), class = "factor"), service_worst_problem = structure(c(3L,
1L, 1L, 1L, 1L, 1L, 2L, 4L, 3L, 3L), .Label = c("Obtaining a judgement",
"Other", "Reporting a offence/crime to the police", "Vehicle registration"
), class = "factor"), Gender = structure(c(2L, 2L, 2L, 2L,
2L, 2L, 2L, 1L, 2L, 2L), .Label = c("Female", "Male"), class = "factor"),
Age = structure(c(3L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 2L), .Label = c("26 - 35",
"36 - 45", "46 - 55"), class = "factor"), Education = structure(c(4L,
2L, 2L, 2L, 2L, 2L, 1L, 3L, 1L, 1L), .Label = c("I do not have any formal education",
"Primary education", "University or post-graduate education",
"Vocational training after Secondary / High School"), class = "factor"),
Madrassa = structure(c(1L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 1L,
1L), .Label = c("No", "Yes, on a regular basis", "Yes, some"
), class = "factor"), Monthly_income = structure(c(2L, 1L,
1L, 1L, 1L, 1L, 4L, 2L, 3L, 3L), .Label = c("20,001 - 25,000 AFN",
"6001 - 8000 AFN", "8001 - 10,000 AFN", "Less than 2,000 AFN"
), class = "factor"), local_influence = structure(c(1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "No", class = "factor"),
basis_local_influence = structure(c(1L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 1L, 1L), .Label = c("", "None of the above"), class = "factor"),
current_occupation = structure(c(1L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L), .Label = c("Other", "Paid worker in any sector"
), class = "factor"), ethinic_group = structure(c(3L, 2L,
2L, 2L, 2L, 2L, 1L, 3L, 3L, 3L), .Label = c("Aimaq", "Pashtun",
"Tajik"), class = "factor"), location = structure(c(1L, 1L,
1L, 1L, 1L, 1L, 2L, 1L, 2L, 2L), .Label = c("Herat PD1 - Dawlat Khana",
"Herat PD9 - Baghcha-e-Mastufi"), class = "factor"), City = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "Herat", class = "factor"),
NarrID = c(173L, 174L, 174L, 174L, 174L, 174L, 175L, 177L,
178L, 178L), Stone.Num = c(1L, 1L, 2L, 3L, 4L, 5L, 4L, 1L,
1L, 2L), NarrID_Stone = c(173.01, 174.01, 174.02, 174.03,
174.04, 174.05, 175.04, 177.01, 178.01, 178.02), Stone.Name.L1 = structure(c(3L,
3L, 4L, 1L, 5L, 2L, 5L, 3L, 3L, 4L), .Label = c("District Officials",
"Malik / Wakil-e-Guzar", "Police", "Provincial Officials",
"Religious Leaders"), class = "factor"), Canvas01.AdjXRightValue = c(0.7299,
0.8994, 0.8615, 0.2399, 0.9103, NA, 0.8757, 0.0916, 0.1725,
0.351), Canvas01.AdjYTopValue = c(0.2903, 0.8374, 0.6583,
0.8183, 0.2167, NA, 0.8374, 0.7678, 0.705, 0.7239), Canvas01.Quadrant = structure(c(3L,
4L, 4L, 2L, 3L, 1L, 4L, 2L, 2L, 2L), .Label = c("", "2. Upper Left",
"3. Lower Right", "4. Upper Right"), class = "factor"),
Canvas02.AdjXRightValue = c(0.2113, 0.8892, 0.8102, 0.1629,
0.8911, NA, 0.9206, 0.7614, 0.4365, 0.143), Canvas02.AdjYTopValue = c(0.2375,
0.8305, 0.7514, 0.8385, 0.1948, NA, 0.2521, 0.8824, 0.5588,
0.7078), Canvas02.Quadrant = structure(c(2L, 5L, 5L, 3L,
4L, 1L, 4L, 5L, 3L, 3L), .Label = c("", "1. Lower Left",
"2. Upper Left", "3. Lower Right", "4. Upper Right"), class = "factor"),
Canvas03.AdjXRightValue = c(0.2945, 0.8503, 0.7177, 0.2971,
0.9026, NA, 0.1442, 0.6663, 0.1856, 0.6509), Canvas03.AdjYTopValue = c(0.2849,
0.7296, 0.7228, 0.7445, 0.1675, NA, 0.836, 0.8469, 0.7808,
0.8319), Canvas03.Quadrant = structure(c(2L, 5L, 5L, 3L,
4L, 1L, 3L, 5L, 3L, 5L), .Label = c("", "1. Lower Left",
"2. Upper Left", "3. Lower Right", "4. Upper Right"), class = "factor"),
Canvas04.AdjXRightValue = c(0.2804, 0.9165, 0.8147, 0.7183,
0.1924, 0.6477, 0.6946, 0.0608, 0.1211, 0.3215), Canvas04.AdjYTopValue = c(0.2808,
0.8114, 0.7282, 0.7064, 0.2767, 0.7391, 0.746, 0.3553, 0.615,
0.6246), Canvas04.Quadrant = structure(c(1L, 3L, 3L, 3L,
1L, 3L, 3L, 1L, 2L, 2L), .Label = c("1. Lower Left", "2. Upper Left",
"4. Upper Right"), class = "factor"), Canvas05.AdjXRightValue = c(0.2817,
0.2078, 0.2065, 0.1205, 0.2958, 0.1166, 0.1115, 0.1532, 0.2642,
0.143), Canvas05.AdjYTopValue = c(0.2535, 0.2167, 0.3122,
0.1455, 0.2399, 0.3094, 0.8169, 0.2789, 0.2883, 0.2453),
Canvas05.Quadrant = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L,
1L, 1L, 1L), .Label = c("1. Lower Left", "2. Upper Left"
), class = "factor")), row.names = c(NA, 10L), class = "data.frame")
并且已经使用 ggplotly() 创建了这个散点图:
ggplotly(
ggplot(df_f, aes(x=Canvas01.AdjXRightValue, y=Canvas01.AdjYTopValue, colour=Gender)) +
geom_point(aes(text=map(paste('<b>Canvas:</b>',"1 size and frequency",
'<br>', '<b>Stone:</b>', Stone.Name.L1,
'<br>', '<b>Quadrant:</b>', Canvas01.Quadrant,
'<br>', '<b>About the Respondents Experience</b>'," ",
'<br>', '<b>Impact:</b>', Impact,
'<br>', '<b>Size of bribe:</b>', Size_bribe,
'<br>', '<b>Type of abuse:</b>', Abuse_type,
'<br>', '<b>Service with worst problem:</b>', service_worst_problem,
'<br>', '<b>About the Respondent</b>'," ",
'<br>', '<b>Gender:</b>', Gender,
'<br>', '<b>Age:</b>', Age,
'<br>', '<b>Education:</b>', Education,
'<br>', '<b>Madrassa:</b>', Madrassa,
'<br>', '<b>Monthly income:</b>', Monthly_income,
'<br>', '<b>Local influence?:</b>', local_influence,
'<br>', '<b>Basis of local influence:</b>', basis_local_influence,
'<br>', '<b>Current occupation:</b>', current_occupation,
'<br>', '<b>Ethnic group:</b>', ethinic_group,
'<br>', '<b>Location:</b>', location,
'<br>', '<b>Default text</b>'," "), HTML)))+
xlab("Asked for small bribes or abused power minimally") +
ylab("Asked for bribes or abused power infrequently") +
ggtitle("1 size and frequency") + geom_hline(aes(yintercept=0.5),colour="black") +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank())+theme(legend.title = element_blank())+
geom_vline(aes(xintercept=0.5), colour="black"))
一切正常,看起来很好,只是我需要在图表的 4 个边添加标题,现在我在底部和左侧有标题,但想在顶部和右侧添加另一个标题。我该怎么做?
所有 4 个面都有标题的图表示例:
最佳答案
这不是一个完整的答案,因为我无法让它与 plotly::ggplotly
一起工作。我希望它能帮助你更进一步
在对 ggplot
的调用中,您可以在 scale_x_continuous()
和 scale_y_continuous( )
函数,如以下代码:
ggplot(df_f, aes(x = Canvas01.AdjXRightValue, y = Canvas01.AdjYTopValue, colour = Gender)) +
geom_point() +
xlab("Asked for small bribes or abused power minimally") +
ylab("Asked for bribes or abused power infrequently") +
ggtitle("1 size and frequency") +
geom_hline(aes(yintercept=0.5),colour="black") +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank())+theme(legend.title = element_blank())+
geom_vline(aes(xintercept=0.5), colour="black") +
scale_x_continuous(sec.axis = dup_axis(name = "Asked for large bribes\nor abused power significantly")) +
scale_y_continuous(sec.axis = dup_axis(name = "Asked for bribes or abused\n their power frequently"))
产生以下情节:
关于r - 在 ggplotly 散点图上添加辅助 x 和 y 轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56360330/
前 R 用户,我曾经通过 ggplotly() 函数广泛地结合 ggplot 和 plot_ly 库来显示数据。 刚到 Python 时,我看到 ggplot 库可用,但在与 plotly 的简单组合
ggplotly 使用 ggplot 删除 geom_line 图的图例。 见例如以下: library(plotly) g % ggplotly() 关于r - ggplotly 从 gg
我有一个 ggplot我试图以非常简约的外观制作线图的问题。我已经摆脱了图例,转而使用每行右侧的文本标签。如果标签不是那么长,它可能不会那么明显,但如果网格线停在最大 x 值(在这种情况下,在 201
我想使用相同的 ggplot 代码以我的数据框中的数字为条件生成 8 个不同的数字。通常我会使用 facet_grid,但在这种情况下,我希望最终得到每个单独数字的 pdf。例如,我想要这里的每一行一
当我在 ggplot 上使用 geom_text 时,与 ggplot 的“填充”选项发生冲突。 这是问题的一个明显例子: library(ggplot2) a=ChickWeight str(a)
是否可以结合使用 ggplot ly 和拼凑而成的ggplot? 例子 这将并排显示两个图 library(ggplot2) library(plotly) library(patchwork) a
我想绘制一个图表,其中 y 轴以百分比表示: p = ggplot(test, aes(x=creation_date, y=value, color=type)) + geom_line(aes
如何去除ggsave中的白边距? 我的问题和Remove white space (i.e., margins) ggplot2 in R一模一样。然而,那里的答案对我来说并不理想。我不想对固定但未知
我有一个带有一些文本层的条形图,在 ggplot 库中一切正常,但现在我想添加一些与 ggplotly 的交互性,但它无法显示文本层 我更新了所有软件包但问题仍然存在 df = read.table(
当我尝试在 ggplot 中为我的箱线图设置自定义宽度时,它工作正常: p=ggplot(iris, aes(x = Species,y=Sepal.Length )) + geom_boxplot(
我正在尝试为 ggplot 密度创建一个图例,将一个组与所有组进行比较。使用此示例 - R: Custom Legend for Multiple Layer ggplot - 我可以使用下面的代码成
所以我试图在一个多面的 ggplot 上编辑 y 值,因为我在编织时在情节上有几个不准确之处。我对 R 和 R Markdown 很陌生,所以我不太明白为什么,例如,美国的 GDP PPP 在美元金额
我需要在 python 条形图的 x 轴 ggplot 上格式化日期。 我该怎么做? 最佳答案 使用 scale_x_date() 格式化 x 轴上的日期。 p = ggplot(aes(x='dat
我想使用 ggplotly因为它的副作用相同ggplot甚至graphics做。我的意思是当我 knitr::knit或 rmarkdown::render我期望的 Rmd 文档 print(obj)
我在下面有一个简单的应用程序,它显示了一个 ggplot。 ggplot 在控制台中生成警告(见底部图片)。我想捕获警告,并将其显示在应用程序的情节下方。 这是我的代码: library(shiny)
如果显示的基本数据集很大(下面的示例工作代码),则在 Shiny 的应用程序中向/从 ggplot 添加/删除图层可能需要一段时间。 问题是: 有没有办法缓存 ggplot(基本图)并添加/删除/修改
我正在组合 ggplot 的多个绘图,使用网格视口(viewport),这是必要的(我相信),因为我想旋转绘图,这在标准 ggplot 中是不可能的,甚至可能是 gridExtra 包。 我想在两个图
我可以使用 lattice 在 R 中绘制相对频率直方图包裹: a <- runif(100) library(lattice) histogram(a) 我想在 ggplot 中获得相同的图形.我试
我需要重新安装 R,但我现在遇到了 ggplot 的一个小问题。我确信有一个简单的解决方案,我感谢所有提示! 我经常使用堆叠面积图,通常我通过定义因子水平并以相反的顺序绘制来获得所需的堆叠和图例顺序。
新的并且坚持使用ggplot: 我有以下数据: tribe rho preference_watermass 1 Luna2 -1.000 hypolimnic 2 OP10I-A1
我是一名优秀的程序员,十分优秀!