使用ggplot2 1.0.0,我按照下面的说明,找出如何绘制不同因素的百分比条形图:
test <- data.frame(
test1 = sample(letters[1:2], 100, replace = TRUE),
test2 = sample(letters[3:8], 100, replace = TRUE)
)
library(ggplot2)
library(scales)
ggplot(test, aes(x= test2, group = test1)) +
geom_bar(aes(y = ..density.., fill = factor(..x..))) +
facet_grid(~test1) +
scale_y_continuous(labels=percent)
Run Code Online (Sandbox Code Playgroud)

但是,在使用时,我似乎无法获得总计数或每个条形图上方的百分比的标签geom_text.
上述代码的正确添加是什么,也保留了y轴的百分比?
我正在尝试创建一个 dplyr 管道来过滤
想象一个数据框jobs,我想从列中过滤出最高级的位置titles:
titles
Chief Executive Officer
Chief Financial Officer
Chief Technical Officer
Manager
Product Manager
Programmer
Scientist
Marketer
Lawyer
Secretary
Run Code Online (Sandbox Code Playgroud)
用于过滤掉它们的 R 代码(直到“经理”)将是......
jobs %>%
filter(!str_detect(title, 'Chief')) %>%
filter(!str_detect(title, 'Manager')) ...
Run Code Online (Sandbox Code Playgroud)
但我仍然想在最终过滤中保留“程序经理”,以生成一个包含所有“较低级别作业”的新数据框,例如
Product Manager
Programmer
Scientist
Marketer
Lawyer
Secretary
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以在除一个特定字符串之外的给定值上指定 str_detect() 过滤器?
假设数据框的列有 1000 个角色,具有各种字符串组合,包括“Manager”,但始终会有针对特定异常的过滤器。
我对JQuery很新,所以我不知道从哪里开始解决这个问题.
我在网站上有一个表格,我希望暂时显示各种占位符并循环浏览它们(模仿用户可以在那里输入的多个选项;例如Alice,Bob,Charles等用于NAME表单输入)点击输入自己的文字.
我发现这个例子 - http://jsfiddle.net/eFjnU/(下面的代码) - 循环文本,但我怎么能将它应用于表单输入区域中的临时占位符?
HTML
<div id="content-1">Sample text 1</div>
<div id="content-2">Sample text 2</div>
<div id="content-3">Sample text 3</div>
<div id="content-4">Sample text 4</div>
<div id="content-5">Sample text 5</div>
<div id="content-6">Sample text 6</div>
<div id="content-7">Sample text 7</div>
Run Code Online (Sandbox Code Playgroud)
JQuery的
var divs = $('div[id^="content-"]').hide(),
i = 0;
(function cycle() {
divs.eq(i).fadeIn(400)
.delay(1000)
.fadeOut(400, cycle);
i = ++i % divs.length;
})();
Run Code Online (Sandbox Code Playgroud)
您可以将上面的div更改为输入,但这将循环整个输入框,我只希望占位符文本淡入/淡出.
编辑1:
例如:
<input type="text" name="whatever" type="text" placeholder="Alice">
<input type="text" name="whatever" type="text" placeholder="Bob">
<input type="text" name="whatever" type="text" placeholder="Charles">
Run Code Online (Sandbox Code Playgroud) 我正在尝试基于对Postgres的最新版本(9.3.4)中包含JSON 的文本列的查询来建立视图,但是出现一个我无法找到任何讨论的错误。
假设该表名为table1,并且特定列json_data具有类似
{"item1": "value1", "item2": "value2", "item3": 3, "item4": 4, "item5": 5}
Run Code Online (Sandbox Code Playgroud)
这是我的查询:
SELECT
json_extract_path_text((table1.json_data)::text,
('item1'::character varying)::text) AS item1
FROM
table1
Run Code Online (Sandbox Code Playgroud)
我得到的错误是
ERROR: function json_extract_path_text(text, text) does not exist
LINE 2: json_extract_path_text((table1.json_data)...
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
Run Code Online (Sandbox Code Playgroud)
我不知道如何解决这个问题。(此外,我有一个相似的视图,在特定表的相似文本列上使用相同的语法,可以完全正常工作。)